Repository navigation
Compilation with clang likely broken? #5281
|
I am trying to compile an App that should make use of Now I am in the progress of switching to clang (on Windows) from here: https://github.com/mstorsjo/llvm-mingw/releases And to me, thix looks correct as My question: Is this a limitation of clang or could/should this also be fixed in |
Replies: 2 comments 4 replies
|
This is very likely not a json.hpp bug but a difference in how libstdc++ (GCC) vs. libc++ (clang/llvm-mingw) handle incomplete types in std::vector. get_to/from_json end up instantiating std::vector’s internals (including pointer arithmetic between elements) for T = CodeAction. That requires CodeAction to be a complete type at the point of instantiation — libstdc++ tends to tolerate this in more situations, while libc++ enforces it strictly (hence the arithmetic on a pointer to an incomplete type error). Given the circular relationship between Diagnostics and CodeAction, the fix is on your side: make sure CodeAction is fully defined before Diagnostics’/PublishDiagnosticsParams’ from_json/get_to machinery is instantiated for the vector containing it (e.g. reorder declarations/includes), or break the cycle by storing CodeAction via std::unique_ptr instead of by value until it’s complete. |
|
I could reproduce this with the actual
Same result with json 3.11.3 and 3.12.0, so the library version does not matter here. The reason: The fix is a pure reordering in
The struct definitions themselves stay where they are. I verified that the patched header compiles with clang/libc++ and with GCC in C++17, C++20 and C++23. (This reply was written by Claude Code.) |
I could reproduce this with the actual
protocol.hfrom the Code::Blocks tree. It is not ajson.hppissue, and it is also not really a clang bug — it only shows up in C++20 mode with libc++:-std=c++17: compiles-std=c++20/-std=c++23: fails with exactly your diagnostic (same note trail:protocol.h:735→FROM_KEY→JSON_SERIALIZE→ forward declaration atprotocol.h:687)Same result with json 3.11.3 and 3.12.0, so the library version does not matter here.
The reason:
Diagnostic(line 689) hasoption<std::vector<CodeAction>>whileCodeActionis only forward-declared (line 687, defined at line 790). The serialize…