clangd / vscode-clangd

Visual Studio Code extension for clangd
https://marketplace.visualstudio.com/items?itemName=llvm-vs-code-extensions.vscode-clangd
MIT License
592 stars 97 forks source link

Clangd server crashes when processing std::ranges::count_if with lambda in VSCode #633

Closed yuyu5333 closed 1 month ago

yuyu5333 commented 1 month ago

Description

Clangd crashes consistently in VSCode when trying to parse a file containing the following line of code:

return (wide ? wide_ulen(str) : std::ranges::count_if(str, [](char c) { return (static_cast<unsigned char>(c) & 0xC0) != 0x80; }));

This line is intended to count characters in a UTF-8 string, excluding continuation bytes. The crash occurs irrespective of the file's other contents.

If you can, provide a minimal chunk of code that shows the problem (either inline, or attach it if larger).

return (wide ? wide_ulen(str) : std::ranges::count_if(str, [](char c) { return (static_cast<unsigned char>(c) & 0xC0) != 0x80; }));

Logs Please attach the clangd log from the "Output" window if you can. If possible, run with --log=verbose - note that the logs will include the contents of open files!

I[15:44:33.191] <-- textDocument/documentSymbol(4)
I[15:44:33.827] --> textDocument/publishDiagnostics
[Error - 15:44:35] The Clang Language Server server crashed 5 times in the last 3 minutes. The server will not be restarted. See the output for more information.
[Error - 15:44:35] Request textDocument/documentSymbol failed.
[object Object]
[Error - 15:44:35] Request textDocument/documentLink failed.
[object Object]
[Error - 15:44:35] Request textDocument/codeAction failed.
[object Object]
[Error - 15:44:35] Request textDocument/documentSymbol failed.
[object Object]
[Error - 15:44:35] Request textDocument/codeAction failed.
[object Object]

System information Clangd version (from the log, or clangd --version): clangd version 10.0.0-4ubuntu1 clangd extension version: v0.1.28 Operating system: Ubuntu Linux 20.04

yuyu5333 commented 1 month ago

VSCode report:

  1. vscode source:clangd : Connection to server got closed. Server will not be restarted.
  2. Client Clang Language Server: connection to server is erroring. Shutting down server.
HighCommander4 commented 1 month ago

Clangd 10 was released in 2020, when clang's support for C++20 code such as std::ranges was fairly unstable, so it's not surprising to see it crash.

Please try the latest version, clangd 18, from https://github.com/clangd/clangd/releases/tag/18.1.3.

yuyu5333 commented 1 month ago

Clangd 10 was released in 2020, when clang's support for C++20 code such as std::ranges was fairly unstable, so it's not surprising to see it crash.

Please try the latest version, clangd 18, from https://github.com/clangd/clangd/releases/tag/18.1.3.

Thank you very much for your answer! ! ! Upgrading clang did solve the problem! ! ! In addition, what I am confused about is that if it is just because clang10 does not support it, then the expected reaction should be that the library reference cannot be found, rather than crashing directly. So is this a potential BUG of clang? If so, it may be better to fix it.

HighCommander4 commented 1 month ago

I agree with you that a crash is always a bug. However, since the crash has gone away in newer versions, the bug has already been fixed.