When I used VSCode+XMake+Clangd+MSVC, clangd confused me.
If I wrote this in xmake.lua:
set_language("c++23")
I could not use std::filesystem. Then I found Clangd expanded the marco __cplusplus to 202400L in main.cpp and to 201402L in other any files, which made me confusing.
Then I wrote this in xmake.lua:
set_language("c++20")
The marco __cplusplus was expanded to 202002L in all files. So that my Clangd could not recognize std::println, althought it is still able to compile.
I thought all the problem were caused by Clangd. But how to solve it?
VSCode 1.90.2, clangd 18.1.3, xmake v2.9.2+HEAD.6b6557c54, VS 17.10.1
compile_commands.json? Among other things it should contain-std=c++??for all files, assuming the build system passes it to the compiler in the first place.compile_commands.json: 1. The argument was/std:c++latest. It was the generation result of "c++23" in xmake.lua. 2. The argument was/std:c++20. It was the generation result of "c++20" in xmake.lua. 3. I replaced the argument with/std:c++23. Then the macro__cpluspluswas expand to201402Lin all the file, including main.cpp/std:c++latestincompile_commands.json. Also Clang seems to not understand MSVC's/std:c++23(only20and below andlatest).