unable using C++23 with CMake+clangd+MSVC+VSCode

167 views Asked by At

I'm using CMake generator and MSVC compiler with VSCode editor while programming C++, but something troubled me when I try to switch language support extension to clangd. It works correctly set CXX_STANDARD to C++20, but when I tried upgrading to C++23, CMake generates "-std:c++latest" instead of "-std:c++23" to compile_commands.json. In my source files, both macro __cplusplus and _MSVC_LANG equals to 201402L, not 2023xxL. (But I can normally compile C++23 features)

Do CMake and clangd support c++23? I found that there was -std:c++23 support for Clang in its official documentation, But it either not works when I manually replaced "-std:c++latest" to "-std:C++23".

My clangd and CMake are in newest versions.


My configurations:

enter image description here

enter image description here


How It works in C++20 standard:

enter image description here

enter image description here


How it doesn't work in C++23 standard: (clangd says it is c++14!)

enter image description here

enter image description here

enter image description here

I tried to manually replaced "-std:c++latest" to "-std:C++23", then upgraded CMake and clangd version newest. But problen still exsits.

1

There are 1 answers

0
HolyBlackCat On

This is a Clangd bug (or this one).

The workaround is to add following to .clangd (config file in your project dir):

CompileFlags:
  Add: ['-std:c++latest']