Skip to content

C++ version is set to latest when setting it to c++23. This results in code getting compiled in c++26 mode with latest clang/msvc

CMake generates wrong c++ version. Our desired c++ version is 23 and not 26. We only noticed this after upgrading to clang 18 that itself now added support for https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2023/p2864r2.pdf a c++26 fix.

PS C:\Users\Ryzen-7950X> cmake --version
cmake version 3.29.0

A simple hello world app that generates compile commands results in:

cmake_minimum_required(VERSION 3.14)

project(Test LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

add_executable(coutTest
  main.cpp
)

results in

{
  "directory": "C:/Users/Ryzen-7950X/Documents/coutTest/build/Desktop_Qt_6_8_0_MSVC2019_64bit-Debug",
  "command": "C:\\PROGRA~1\\MICROS~3\\2022\\COMMUN~1\\VC\\Tools\\MSVC\\1440~1.338\\bin\\HostX64\\x64\\cl.exe  /nologo  [...] -std:c++latest 
}

when switching to c++20

cmake_minimum_required(VERSION 3.14)

project(Test LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

add_executable(coutTest
  main.cpp
)

results in

[
{
  "directory": "C:/Users/Ryzen-7950X/Documents/coutTest/build/Desktop_Qt_6_8_0_MSVC2019_64bit-Debug",
  "command": "C:\\PROGRA~1\\MICROS~3\\2022\\COMMUN~1\\VC\\Tools\\MSVC\\1440~1.338\\bin\\HostX64\\x64\\cl.exe  /nologo [...] -std:c++20 
}
]
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information