1

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

asked Jun 24, 2024 at 9:57
3
  • 3
    Does your build system generate 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. Commented Jun 24, 2024 at 10:00
  • It did. And there are three scenarios int the 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 __cplusplus was expand to 201402L in all the file, including main.cpp Commented Jun 24, 2024 at 11:12
  • There's this old bug about Clang not understanding /std:c++latest in compile_commands.json. Also Clang seems to not understand MSVC's /std:c++23 (only 20 and below and latest). Commented Jun 24, 2024 at 11:25

0

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.