clangd / vscode-clangd

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

Crash when parsing constructor with multiple requires expressions #661

Closed vis4rd closed 1 month ago

vis4rd commented 3 months ago

I am using quite heavily templated class, sometimes with multiple requires expressions in a single method and clangd extension (in LSP mode?) crashes because of that.

What is interesting, clangd --tweaks=std=c++20 -log=verbose --check=PackedVariable.hpp does not yield any errors.

Code snippet:

PackedVariable.hpp (Click to expand) ```cpp #include #include #include #include #include #include #include using PackedVariableSection = std::size_t; #define _pv_runtime_assert(expression, fmt, ...) \ (assert((expression) || !fprintf(stderr, ("Assertion message: " fmt "\n"), ##__VA_ARGS__))) namespace util { template requires((I < sizeof...(Ts)) and (sizeof...(Ts) > 0)) constexpr decltype(auto) value_at(Ts&&... ts) noexcept { return std::get(std::forward_as_tuple(std::forward(ts)...)); } } // namespace util namespace detail { template concept ValidSections = ((Sections + ...) <= (sizeof(T) * 8)) and ((Sections > 0) and ...); template concept ValidIndex = (Index < sizeof...(Sections)) and (Index >= 0); template concept ValidArgs = ((IndicesSize == ArgsSize) and (IndicesSize <= sizeof...(Sections))); } // namespace detail namespace workaround { // Right shift on signed integers does not work correctly in some cases on compilers: // - GCC 10 and maybe below (did not check), // - Clang 14-16. // // MSVC has never been checked. // Clang 17 and above have never been checked. #ifdef PACKED_VARIABLE_ENABLE_COMPILER_CHECK #ifndef __clang_major__ #define __clang_major__ 0 #endif #ifndef __GNUC__ #define __GNUC__ 0 #endif namespace detail { template concept WorkingGnuCompiler = std::signed_integral and (__GNUC__ >= 11); template concept WorkingClangCompiler = std::signed_integral and (__clang_major__ <= 13) and (__clang_major__ > 0); } // namespace detail template concept WorkingCompiler = std::unsigned_integral or detail::WorkingGnuCompiler or detail::WorkingClangCompiler; #else template concept WorkingCompiler = true; #endif } // namespace workaround template requires(detail::ValidSections and workaround::WorkingCompiler) class PackedVariable final { public: using value_type = T; public: constexpr PackedVariable(std::convertible_to auto&&... values) requires(sizeof...(Sections) >= sizeof...(values)); template requires detail::ValidIndex constexpr void set(std::convertible_to auto value); template requires detail::ValidIndex constexpr value_type at() const; constexpr value_type get() const; friend constexpr std::ostream& operator<<(std::ostream& os, PackedVariable pv) { os << "0b" << std::bitset(pv.m_value); return os; } private: template requires detail::ValidIndex constexpr value_type left_padding() const; template requires detail::ValidIndex constexpr value_type right_padding() const; template requires detail::ValidArgs constexpr void set_sections_on_construction(std::index_sequence, Args&&... args); private: value_type m_value{}; }; template requires(detail::ValidSections and workaround::WorkingCompiler) constexpr PackedVariable::PackedVariable(std::convertible_to auto&&... values) requires(sizeof...(Sections) >= sizeof...(values)) { this->set_sections_on_construction(std::make_index_sequence(), values...); } template requires(detail::ValidSections and workaround::WorkingCompiler) template requires detail::ValidIndex constexpr void PackedVariable::set(std::convertible_to auto value) { _pv_runtime_assert(value >= 0, "Value %d must be greater or equal to 0", value); _pv_runtime_assert( value <= ((1 << util::value_at(Sections...)) - 1), "Value %d out of range in section %d (bitsize is %d while max allowed is %d)", value, Index, (static_cast(std::log2(value)) + 1), util::value_at(Sections...)); const auto left_shift = this->right_padding(); constexpr value_type width = util::value_at(Sections...); constexpr value_type mask = (1 << width) - 1; m_value |= ((value & mask) << left_shift); } template requires(detail::ValidSections and workaround::WorkingCompiler) template requires detail::ValidIndex constexpr T PackedVariable::at() const { const auto right_shift = this->right_padding(); constexpr value_type width = util::value_at(Sections...); constexpr value_type mask = (1 << width) - 1; return ((m_value >> right_shift) & mask); } template requires(detail::ValidSections and workaround::WorkingCompiler) constexpr T PackedVariable::get() const { return m_value; } template requires(detail::ValidSections and workaround::WorkingCompiler) template requires detail::ValidIndex constexpr T PackedVariable::left_padding() const { constexpr auto sum = []( std::index_sequence, Args&&... args) -> value_type { constexpr auto value_below_index = [](std::size_t index, Arg&& arg) -> value_type { return (index >= Index) ? 0 : arg; }; return (value_below_index(Indices, std::forward(args)) + ...); }; return sum(std::make_index_sequence(), Sections...); } template requires(detail::ValidSections and workaround::WorkingCompiler) template requires detail::ValidIndex constexpr T PackedVariable::right_padding() const { constexpr auto total_width = sizeof(value_type) * 8; constexpr value_type width = util::value_at(Sections...); return total_width - this->left_padding() - width; } template requires(detail::ValidSections and workaround::WorkingCompiler) template requires detail::ValidArgs constexpr void PackedVariable::set_sections_on_construction( std::index_sequence, Args&&... args) { (this->set(args), ...); } ```

Logs

Log from VSCode clangd output view:

(Click to expand) ``` I[20:27:30.824] (built by Brecht Sanders, r3) clangd version 18.1.8 I[20:27:30.824] Features: windows I[20:27:30.824] PID: 14360 I[20:27:30.824] Working directory: s:/Code/CPP/packed_variable I[20:27:30.824] argv[0]: S:/Environment/Compilers/mingw64_12.0.0_gcc_14.1.0_clang_18.1.8_ucrt/bin/clangd.exe I[20:27:30.824] argv[1]: --header-insertion I[20:27:30.824] argv[2]: never I[20:27:30.826] Starting LSP over stdin/stdout I[20:27:30.826] <-- initialize(0) I[20:27:30.828] --> reply:initialize(0) 2 ms I[20:27:30.829] <-- initialized I[20:27:30.831] <-- textDocument/didOpen I[20:27:30.832] <-- textDocument/didOpen I[20:27:30.832] <-- textDocument/documentSymbol(1) I[20:27:30.832] <-- textDocument/codeAction(2) I[20:27:30.837] --> textDocument/publishDiagnostics I[20:27:30.837] Loaded compilation database from s:/Code/CPP/packed_variable/build/compile_commands.json I[20:27:30.838] ASTWorker building file s:/Code/CPP/packed_variable/main.cpp version 7 with command [S:/Code/CPP/packed_variable/build] S:/Environment/Compilers/mingw64_11.0.0_gcc_13.1.0_clang_16.0.5_msvcrt/bin/g++.exe --driver-mode=g++ -IS:/Code/CPP/packed_variable/include -O3 -DNDEBUG -std=gnu++20 -o "CMakeFiles\\PackedVariableTest.dir\\main.cpp.obj" -c -std=c++20 -resource-dir=S:/Environment/Compilers/mingw64_12.0.0_gcc_14.1.0_clang_18.1.8_ucrt/lib/clang/18 -- s:/Code/CPP/packed_variable/main.cpp I[20:27:30.838] ASTWorker building file s:/Code/CPP/packed_variable/include/PackedVariable.hpp version 4 with command inferred from S:/Code/CPP/packed_variable/main.cpp [S:/Code/CPP/packed_variable/build] S:/Environment/Compilers/mingw64_11.0.0_gcc_13.1.0_clang_16.0.5_msvcrt/bin/g++.exe --driver-mode=g++ -IS:/Code/CPP/packed_variable/include -O3 -DNDEBUG -c -std=gnu++20 -std=c++20 -resource-dir=S:/Environment/Compilers/mingw64_12.0.0_gcc_14.1.0_clang_18.1.8_ucrt/lib/clang/18 -- s:/Code/CPP/packed_variable/include/PackedVariable.hpp I[20:27:30.838] --> textDocument/publishDiagnostics I[20:27:30.838] --> window/workDoneProgress/create(0) I[20:27:30.838] Enqueueing 1 commands for indexing I[20:27:30.838] <-- reply(0) I[20:27:30.838] --> $/progress I[20:27:30.838] --> $/progress I[20:27:30.839] --> $/progress I[20:27:30.839] --> $/progress I[20:27:30.839] --> $/progress I[20:27:30.839] --> textDocument/clangd.fileStatus I[20:27:30.839] --> textDocument/clangd.fileStatus I[20:27:30.843] <-- textDocument/documentLink(3) I[20:27:30.843] <-- textDocument/inlayHint(4) PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace. Stack dump: 0. S:/Code/CPP/packed_variable/include/PackedVariable.hpp:130:52: current parser token '{' Signalled while building preamble Filename: S:/Code/CPP/packed_variable/main.cpp Directory: S:/Code/CPP/packed_variable/build Command Line: S:/Environment/Compilers/mingw64_11.0.0_gcc_13.1.0_clang_16.0.5_msvcrt/bin/g++.exe --driver-mode=g++ -IS:/Code/CPP/packed_variable/include -O3 -DNDEBUG -std=gnu++20 -o CMakeFiles\PackedVariableTest.dir\main.cpp.obj -c -std=c++20 -resource-dir=S:/Environment/Compilers/mingw64_12.0.0_gcc_14.1.0_clang_18.1.8_ucrt/lib/clang/18 -- s:/Code/CPP/packed_variable/main.cpp Version: 7 [Info - 8:27:31 PM] Connection to server got closed. Server will restart. [Error - 8:27:31 PM] Request textDocument/documentSymbol failed. [object Object] [Error - 8:27:31 PM] Request textDocument/codeAction failed. [object Object] [Error - 8:27:31 PM] Request textDocument/documentLink failed. [object Object] [Error - 8:27:31 PM] Request textDocument/inlayHint failed. [object Object] I[20:27:31.307] (built by Brecht Sanders, r3) clangd version 18.1.8 I[20:27:31.307] Features: windows I[20:27:31.307] PID: 18512 I[20:27:31.307] Working directory: s:/Code/CPP/packed_variable I[20:27:31.307] argv[0]: S:/Environment/Compilers/mingw64_12.0.0_gcc_14.1.0_clang_18.1.8_ucrt/bin/clangd.exe I[20:27:31.307] argv[1]: --header-insertion I[20:27:31.307] argv[2]: never I[20:27:31.309] Starting LSP over stdin/stdout I[20:27:31.309] <-- initialize(0) I[20:27:31.311] --> reply:initialize(0) 1 ms I[20:27:31.312] <-- initialized I[20:27:31.314] <-- textDocument/didOpen I[20:27:31.314] <-- textDocument/didOpen I[20:27:31.315] --> textDocument/publishDiagnostics I[20:27:31.315] Loaded compilation database from s:/Code/CPP/packed_variable/build/compile_commands.json I[20:27:31.316] ASTWorker building file s:/Code/CPP/packed_variable/main.cpp version 7 with command [S:/Code/CPP/packed_variable/build] S:/Environment/Compilers/mingw64_11.0.0_gcc_13.1.0_clang_16.0.5_msvcrt/bin/g++.exe --driver-mode=g++ -IS:/Code/CPP/packed_variable/include -O3 -DNDEBUG -std=gnu++20 -o "CMakeFiles\\PackedVariableTest.dir\\main.cpp.obj" -c -std=c++20 -resource-dir=S:/Environment/Compilers/mingw64_12.0.0_gcc_14.1.0_clang_18.1.8_ucrt/lib/clang/18 -- s:/Code/CPP/packed_variable/main.cpp I[20:27:31.316] ASTWorker building file s:/Code/CPP/packed_variable/include/PackedVariable.hpp version 4 with command inferred from S:/Code/CPP/packed_variable/main.cpp [S:/Code/CPP/packed_variable/build] S:/Environment/Compilers/mingw64_11.0.0_gcc_13.1.0_clang_16.0.5_msvcrt/bin/g++.exe --driver-mode=g++ -IS:/Code/CPP/packed_variable/include -O3 -DNDEBUG -c -std=gnu++20 -std=c++20 -resource-dir=S:/Environment/Compilers/mingw64_12.0.0_gcc_14.1.0_clang_18.1.8_ucrt/lib/clang/18 -- s:/Code/CPP/packed_variable/include/PackedVariable.hpp I[20:27:31.316] --> textDocument/publishDiagnostics I[20:27:31.316] --> window/workDoneProgress/create(0) I[20:27:31.316] Enqueueing 1 commands for indexing I[20:27:31.316] <-- reply(0) I[20:27:31.316] --> $/progress I[20:27:31.316] --> $/progress I[20:27:31.317] --> $/progress I[20:27:31.317] --> $/progress I[20:27:31.317] --> $/progress I[20:27:31.317] --> textDocument/clangd.fileStatus I[20:27:31.317] --> textDocument/clangd.fileStatus I[20:27:31.318] <-- textDocument/documentSymbol(1) I[20:27:31.319] <-- textDocument/codeAction(2) I[20:27:31.324] <-- textDocument/documentLink(3) I[20:27:31.325] <-- textDocument/inlayHint(4) I[20:27:31.590] <-- textDocument/foldingRange(5) I[20:27:31.592] --> reply:textDocument/foldingRange(5) 1 ms I[20:27:31.627] <-- textDocument/documentSymbol(6) PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace. Stack dump: 0. S:/Code/CPP/packed_variable/include/PackedVariable.hpp:130:52: current parser token '{' Signalled while building preamble Filename: S:/Code/CPP/packed_variable/main.cpp Directory: S:/Code/CPP/packed_variable/build Command Line: S:/Environment/Compilers/mingw64_11.0.0_gcc_13.1.0_clang_16.0.5_msvcrt/bin/g++.exe --driver-mode=g++ -IS:/Code/CPP/packed_variable/include -O3 -DNDEBUG -std=gnu++20 -o CMakeFiles\PackedVariableTest.dir\main.cpp.obj -c -std=c++20 -resource-dir=S:/Environment/Compilers/mingw64_12.0.0_gcc_14.1.0_clang_18.1.8_ucrt/lib/clang/18 -- s:/Code/CPP/packed_variable/main.cpp Version: 7 [Info - 8:27:31 PM] Connection to server got closed. Server will restart. [Error - 8:27:31 PM] Request textDocument/documentSymbol failed. [object Object] [Error - 8:27:31 PM] Request textDocument/codeAction failed. [object Object] [Error - 8:27:31 PM] Request textDocument/documentLink failed. [object Object] [Error - 8:27:31 PM] Request textDocument/inlayHint failed. [object Object] [Error - 8:27:31 PM] Request textDocument/documentSymbol failed. [object Object] I[20:27:31.736] (built by Brecht Sanders, r3) clangd version 18.1.8 I[20:27:31.736] Features: windows I[20:27:31.736] PID: 432 I[20:27:31.736] Working directory: s:/Code/CPP/packed_variable I[20:27:31.736] argv[0]: S:/Environment/Compilers/mingw64_12.0.0_gcc_14.1.0_clang_18.1.8_ucrt/bin/clangd.exe I[20:27:31.736] argv[1]: --header-insertion I[20:27:31.736] argv[2]: never I[20:27:31.738] Starting LSP over stdin/stdout I[20:27:31.738] <-- initialize(0) I[20:27:31.740] --> reply:initialize(0) 1 ms I[20:27:31.741] <-- initialized I[20:27:31.742] <-- textDocument/didOpen I[20:27:31.743] <-- textDocument/didOpen I[20:27:31.743] <-- textDocument/documentSymbol(1) I[20:27:31.743] <-- textDocument/codeAction(2) I[20:27:31.744] --> textDocument/publishDiagnostics I[20:27:31.744] Loaded compilation database from s:/Code/CPP/packed_variable/build/compile_commands.json I[20:27:31.744] ASTWorker building file s:/Code/CPP/packed_variable/include/PackedVariable.hpp version 4 with command inferred from S:/Code/CPP/packed_variable/main.cpp [S:/Code/CPP/packed_variable/build] S:/Environment/Compilers/mingw64_11.0.0_gcc_13.1.0_clang_16.0.5_msvcrt/bin/g++.exe --driver-mode=g++ -IS:/Code/CPP/packed_variable/include -O3 -DNDEBUG -c -std=gnu++20 -std=c++20 -resource-dir=S:/Environment/Compilers/mingw64_12.0.0_gcc_14.1.0_clang_18.1.8_ucrt/lib/clang/18 -- s:/Code/CPP/packed_variable/include/PackedVariable.hpp I[20:27:31.744] ASTWorker building file s:/Code/CPP/packed_variable/main.cpp version 7 with command [S:/Code/CPP/packed_variable/build] S:/Environment/Compilers/mingw64_11.0.0_gcc_13.1.0_clang_16.0.5_msvcrt/bin/g++.exe --driver-mode=g++ -IS:/Code/CPP/packed_variable/include -O3 -DNDEBUG -std=gnu++20 -o "CMakeFiles\\PackedVariableTest.dir\\main.cpp.obj" -c -std=c++20 -resource-dir=S:/Environment/Compilers/mingw64_12.0.0_gcc_14.1.0_clang_18.1.8_ucrt/lib/clang/18 -- s:/Code/CPP/packed_variable/main.cpp I[20:27:31.745] --> textDocument/publishDiagnostics I[20:27:31.745] --> window/workDoneProgress/create(0) I[20:27:31.745] Enqueueing 1 commands for indexing I[20:27:31.745] <-- reply(0) I[20:27:31.745] --> $/progress I[20:27:31.745] --> $/progress I[20:27:31.745] --> $/progress I[20:27:31.745] --> $/progress I[20:27:31.745] --> $/progress I[20:27:31.746] --> textDocument/clangd.fileStatus I[20:27:31.746] --> textDocument/clangd.fileStatus I[20:27:31.748] <-- textDocument/documentLink(3) I[20:27:31.748] <-- textDocument/inlayHint(4) I[20:27:32.007] <-- textDocument/foldingRange(5) I[20:27:32.008] --> reply:textDocument/foldingRange(5) 0 ms I[20:27:32.047] <-- textDocument/documentSymbol(6) PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace. Stack dump: 0. S:/Code/CPP/packed_variable/include/PackedVariable.hpp:130:52: current parser token '{' Signalled while building preamble Filename: S:/Code/CPP/packed_variable/main.cpp Directory: S:/Code/CPP/packed_variable/build Command Line: S:/Environment/Compilers/mingw64_11.0.0_gcc_13.1.0_clang_16.0.5_msvcrt/bin/g++.exe --driver-mode=g++ -IS:/Code/CPP/packed_variable/include -O3 -DNDEBUG -std=gnu++20 -o CMakeFiles\PackedVariableTest.dir\main.cpp.obj -c -std=c++20 -resource-dir=S:/Environment/Compilers/mingw64_12.0.0_gcc_14.1.0_clang_18.1.8_ucrt/lib/clang/18 -- s:/Code/CPP/packed_variable/main.cpp Version: 7 [Info - 8:27:32 PM] Connection to server got closed. Server will restart. [Error - 8:27:32 PM] Request textDocument/documentSymbol failed. [object Object] [Error - 8:27:32 PM] Request textDocument/codeAction failed. [object Object] [Error - 8:27:32 PM] Request textDocument/documentLink failed. [object Object] [Error - 8:27:32 PM] Request textDocument/inlayHint failed. [object Object] [Error - 8:27:32 PM] Request textDocument/documentSymbol failed. [object Object] I[20:27:32.160] (built by Brecht Sanders, r3) clangd version 18.1.8 I[20:27:32.161] Features: windows I[20:27:32.161] PID: 7364 I[20:27:32.161] Working directory: s:/Code/CPP/packed_variable I[20:27:32.161] argv[0]: S:/Environment/Compilers/mingw64_12.0.0_gcc_14.1.0_clang_18.1.8_ucrt/bin/clangd.exe I[20:27:32.161] argv[1]: --header-insertion I[20:27:32.161] argv[2]: never I[20:27:32.162] Starting LSP over stdin/stdout I[20:27:32.162] <-- initialize(0) I[20:27:32.164] --> reply:initialize(0) 1 ms I[20:27:32.165] <-- initialized I[20:27:32.166] <-- textDocument/didOpen I[20:27:32.166] <-- textDocument/didOpen I[20:27:32.167] --> textDocument/publishDiagnostics I[20:27:32.168] Loaded compilation database from s:/Code/CPP/packed_variable/build/compile_commands.json I[20:27:32.168] <-- textDocument/documentSymbol(1) I[20:27:32.168] ASTWorker building file s:/Code/CPP/packed_variable/include/PackedVariable.hpp version 4 with command inferred from S:/Code/CPP/packed_variable/main.cpp [S:/Code/CPP/packed_variable/build] S:/Environment/Compilers/mingw64_11.0.0_gcc_13.1.0_clang_16.0.5_msvcrt/bin/g++.exe --driver-mode=g++ -IS:/Code/CPP/packed_variable/include -O3 -DNDEBUG -c -std=gnu++20 -std=c++20 -resource-dir=S:/Environment/Compilers/mingw64_12.0.0_gcc_14.1.0_clang_18.1.8_ucrt/lib/clang/18 -- s:/Code/CPP/packed_variable/include/PackedVariable.hpp I[20:27:32.168] ASTWorker building file s:/Code/CPP/packed_variable/main.cpp version 7 with command [S:/Code/CPP/packed_variable/build] S:/Environment/Compilers/mingw64_11.0.0_gcc_13.1.0_clang_16.0.5_msvcrt/bin/g++.exe --driver-mode=g++ -IS:/Code/CPP/packed_variable/include -O3 -DNDEBUG -std=gnu++20 -o "CMakeFiles\\PackedVariableTest.dir\\main.cpp.obj" -c -std=c++20 -resource-dir=S:/Environment/Compilers/mingw64_12.0.0_gcc_14.1.0_clang_18.1.8_ucrt/lib/clang/18 -- s:/Code/CPP/packed_variable/main.cpp I[20:27:32.169] --> textDocument/publishDiagnostics I[20:27:32.169] --> window/workDoneProgress/create(0) I[20:27:32.169] Enqueueing 1 commands for indexing I[20:27:32.169] <-- textDocument/codeAction(2) I[20:27:32.169] <-- reply(0) I[20:27:32.169] --> $/progress I[20:27:32.169] --> $/progress I[20:27:32.169] --> $/progress I[20:27:32.169] --> $/progress I[20:27:32.170] --> $/progress I[20:27:32.170] --> textDocument/clangd.fileStatus I[20:27:32.170] --> textDocument/clangd.fileStatus I[20:27:32.174] <-- textDocument/documentLink(3) I[20:27:32.174] <-- textDocument/inlayHint(4) I[20:27:32.437] <-- textDocument/foldingRange(5) I[20:27:32.437] --> reply:textDocument/foldingRange(5) 0 ms I[20:27:32.480] <-- textDocument/documentSymbol(6) PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace. Stack dump: 0. S:/Code/CPP/packed_variable/include/PackedVariable.hpp:130:52: current parser token '{' Signalled while building preamble Filename: S:/Code/CPP/packed_variable/main.cpp Directory: S:/Code/CPP/packed_variable/build Command Line: S:/Environment/Compilers/mingw64_11.0.0_gcc_13.1.0_clang_16.0.5_msvcrt/bin/g++.exe --driver-mode=g++ -IS:/Code/CPP/packed_variable/include -O3 -DNDEBUG -std=gnu++20 -o CMakeFiles\PackedVariableTest.dir\main.cpp.obj -c -std=c++20 -resource-dir=S:/Environment/Compilers/mingw64_12.0.0_gcc_14.1.0_clang_18.1.8_ucrt/lib/clang/18 -- s:/Code/CPP/packed_variable/main.cpp Version: 7 [Info - 8:27:32 PM] Connection to server got closed. Server will restart. [Error - 8:27:32 PM] Request textDocument/documentSymbol failed. [object Object] [Error - 8:27:32 PM] Request textDocument/codeAction failed. [object Object] [Error - 8:27:32 PM] Request textDocument/documentLink failed. [object Object] [Error - 8:27:32 PM] Request textDocument/inlayHint failed. [object Object] [Error - 8:27:32 PM] Request textDocument/documentSymbol failed. [object Object] I[20:27:32.585] (built by Brecht Sanders, r3) clangd version 18.1.8 I[20:27:32.586] Features: windows I[20:27:32.586] PID: 17756 I[20:27:32.586] Working directory: s:/Code/CPP/packed_variable I[20:27:32.586] argv[0]: S:/Environment/Compilers/mingw64_12.0.0_gcc_14.1.0_clang_18.1.8_ucrt/bin/clangd.exe I[20:27:32.586] argv[1]: --header-insertion I[20:27:32.586] argv[2]: never I[20:27:32.587] Starting LSP over stdin/stdout I[20:27:32.588] <-- initialize(0) I[20:27:32.589] --> reply:initialize(0) 1 ms I[20:27:32.590] <-- initialized I[20:27:32.592] <-- textDocument/didOpen I[20:27:32.593] <-- textDocument/didOpen I[20:27:32.593] <-- textDocument/documentSymbol(1) I[20:27:32.593] <-- textDocument/codeAction(2) I[20:27:32.593] --> textDocument/publishDiagnostics I[20:27:32.593] Loaded compilation database from s:/Code/CPP/packed_variable/build/compile_commands.json I[20:27:32.594] ASTWorker building file s:/Code/CPP/packed_variable/main.cpp version 7 with command [S:/Code/CPP/packed_variable/build] S:/Environment/Compilers/mingw64_11.0.0_gcc_13.1.0_clang_16.0.5_msvcrt/bin/g++.exe --driver-mode=g++ -IS:/Code/CPP/packed_variable/include -O3 -DNDEBUG -std=gnu++20 -o "CMakeFiles\\PackedVariableTest.dir\\main.cpp.obj" -c -std=c++20 -resource-dir=S:/Environment/Compilers/mingw64_12.0.0_gcc_14.1.0_clang_18.1.8_ucrt/lib/clang/18 -- s:/Code/CPP/packed_variable/main.cpp I[20:27:32.594] ASTWorker building file s:/Code/CPP/packed_variable/include/PackedVariable.hpp version 4 with command inferred from S:/Code/CPP/packed_variable/main.cpp [S:/Code/CPP/packed_variable/build] S:/Environment/Compilers/mingw64_11.0.0_gcc_13.1.0_clang_16.0.5_msvcrt/bin/g++.exe --driver-mode=g++ -IS:/Code/CPP/packed_variable/include -O3 -DNDEBUG -c -std=gnu++20 -std=c++20 -resource-dir=S:/Environment/Compilers/mingw64_12.0.0_gcc_14.1.0_clang_18.1.8_ucrt/lib/clang/18 -- s:/Code/CPP/packed_variable/include/PackedVariable.hpp I[20:27:32.594] --> textDocument/publishDiagnostics I[20:27:32.594] --> window/workDoneProgress/create(0) I[20:27:32.594] Enqueueing 1 commands for indexing I[20:27:32.595] <-- reply(0) I[20:27:32.595] --> $/progress I[20:27:32.595] --> $/progress I[20:27:32.595] --> $/progress I[20:27:32.595] --> $/progress I[20:27:32.595] --> $/progress I[20:27:32.596] --> textDocument/clangd.fileStatus I[20:27:32.596] --> textDocument/clangd.fileStatus I[20:27:32.597] <-- textDocument/documentLink(3) I[20:27:32.598] <-- textDocument/inlayHint(4) I[20:27:32.860] <-- textDocument/foldingRange(5) I[20:27:32.861] --> reply:textDocument/foldingRange(5) 1 ms I[20:27:32.896] <-- textDocument/documentSymbol(6) PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace. Stack dump: 0. S:/Code/CPP/packed_variable/include/PackedVariable.hpp:130:52: current parser token '{' Signalled while building preamble Filename: S:/Code/CPP/packed_variable/main.cpp Directory: S:/Code/CPP/packed_variable/build Command Line: S:/Environment/Compilers/mingw64_11.0.0_gcc_13.1.0_clang_16.0.5_msvcrt/bin/g++.exe --driver-mode=g++ -IS:/Code/CPP/packed_variable/include -O3 -DNDEBUG -std=gnu++20 -o CMakeFiles\PackedVariableTest.dir\main.cpp.obj -c -std=c++20 -resource-dir=S:/Environment/Compilers/mingw64_12.0.0_gcc_14.1.0_clang_18.1.8_ucrt/lib/clang/18 -- s:/Code/CPP/packed_variable/main.cpp Version: 7 [Error - 8:27:32 PM] 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 - 8:27:32 PM] Request textDocument/documentSymbol failed. [object Object] [Error - 8:27:32 PM] Request textDocument/codeAction failed. [object Object] [Error - 8:27:32 PM] Request textDocument/documentLink failed. [object Object] [Error - 8:27:32 PM] Request textDocument/inlayHint failed. [object Object] [Error - 8:27:32 PM] Request textDocument/documentSymbol failed. [object Object] ```

Particularly interesting part:

PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.  S:/Code/CPP/packed_variable/include/PackedVariable.hpp:130:52: current parser token '{'
Signalled while building preamble
  Filename: S:/Code/CPP/packed_variable/main.cpp
  Directory: S:/Code/CPP/packed_variable/build
  Command Line: S:/Environment/Compilers/mingw64_11.0.0_gcc_13.1.0_clang_16.0.5_msvcrt/bin/g++.exe --driver-mode=g++ -IS:/Code/CPP/packed_variable/include -O3 -DNDEBUG -std=gnu++20 -o CMakeFiles\PackedVariableTest.dir\main.cpp.obj -c -std=c++20 -resource-dir=S:/Environment/Compilers/mingw64_12.0.0_gcc_14.1.0_clang_18.1.8_ucrt/lib/clang/18 -- s:/Code/CPP/packed_variable/main.cpp
  Version: 7
[Error - 8:27:32 PM] 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.

Looks like it has problems with parsing whatever is after requires(sizeof...(Sections) >= sizeof...(values)).

Logs mention compile_commands.json and main.cpp, where the header is included, so adding them as well:

compile_commands.json (click to expand) Generated by CMake with VSCode CMake extension. ```json [ { "directory": "S:/Code/CPP/packed_variable/build", "command": "S:\\Environment\\Compilers\\mingw64_11.0.0_gcc_13.1.0_clang_16.0.5_msvcrt\\bin\\g++.exe @CMakeFiles/PackedVariableTest.dir/includes_CXX.rsp -O3 -DNDEBUG -std=gnu++20 -o CMakeFiles\\PackedVariableTest.dir\\main.cpp.obj -c S:\\Code\\CPP\\packed_variable\\main.cpp", "file": "S:/Code/CPP/packed_variable/main.cpp", "output": "CMakeFiles/PackedVariableTest.dir/main.cpp.obj" } ] ```
main.cpp (click to expand) ```cpp #include #include #include int main() { PackedVariable pv1{127, 1, 7, 2, 0, 7}; PackedVariable pv2{127, 1, 7, 2, 0, 7}; PackedVariable pv3 = {127}; std::cout << "pv1 = " << pv1.at<0>() << "\n"; std::cout << "pv1 = " << pv1.at<1>() << "\n"; std::cout << "pv1 = " << pv1.at<2>() << "\n"; std::cout << "pv1 = " << pv1.at<3>() << "\n"; std::cout << "pv1 = " << pv1.get() << "\n"; std::cout << "pv1 = " << pv1 << "\n"; std::cout << "\n"; std::cout << "pv2 = " << pv2.at<0>() << "\n"; std::cout << "pv2 = " << pv2.at<1>() << "\n"; std::cout << "pv2 = " << pv2.at<2>() << "\n"; std::cout << "pv2 = " << pv2.at<3>() << "\n"; std::cout << "pv2 = " << pv2.get() << "\n"; std::cout << "pv2 = " << pv2 << "\n"; static_assert(sizeof(pv1) == sizeof(std::uint16_t)); static_assert(sizeof(pv2) == sizeof(std::int16_t)); std::cout << std::endl; return 0; } ```
.clangd (click to expand) ```yaml --- Diagnostics: UnusedIncludes: Strict CompileFlags: Add: [ -std=c++20 ] ... ```

System information

Output of clangd --version:

(built by Brecht Sanders) clangd version 16.0.5
Features: windows
Platform: x86_64-w64-windows-gnu; target=x86_64-w64-mingw32

VSCode version:

Version: 1.91.1 (user setup)
Commit: f1e16e1e6214d7c44d078b1f0607b2388f29d729
Date: 2024-07-09T22:06:49.809Z
Electron: 29.4.0
ElectronBuildId: 9728852
Chromium: 122.0.6261.156
Node.js: 20.9.0
V8: 12.2.281.27-electron.0
OS: Windows_NT x64 10.0.22631

Editor/LSP plugin: clangd extension

Operating system: Windows 11 Home 23H2 64-bit

HighCommander4 commented 2 months ago

Thanks for the report.

I can reproduce this crash with clangd 18, but it seems to be fixed in clangd 19.

While clangd 19 is not released yet, pre-release versions can be obtained from https://github.com/clangd/clangd/releases.

vis4rd commented 1 month ago

Hi, looks like it is a problem of clangd and not this extension then, sorry! It works with clangd 19. Thank you.