clangd / clangd

clangd language server

Home Page:https://clangd.llvm.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

/std:c++latest not preserved when transferring compile command

sam-mccall opened this issue · comments

InterpolatingCompilationDatabase will translate clang --driver-mode=cl /std:c++latest foo.cpp into clang --driver-mode=cl foo.hpp.

This is because we expect the value after "/std:" to name a language version, but in MSVC-compat mode it's a hardcoded table in the driver instead.

I figured out a similar issue with msvc 16.11.3 for the source file it is called correctly, but when clangd is parsing the header file, it omits it.

This is still an issue as of clangd 14.0.5 and msvc 17.3.4. We use clang-cl, our CompilationDatabase / compiler_commands.json specify -std:c++latest and the clangd invocation (via vscode-clangd) output omits the argument unless we redundantly configure our .clangd config file like:

CompileFlags:
Add: [
"-std:c++latest"
]
CompilationDatabase: "C:/path/to/cmake/out/folder/with/compiler_commands"

For recent language standards, msvc does name a language version in a way that seems 1:1 mappable to my eye.

/std:c++14
/std:c++17
/std:c++20
/std:c++latest

c++latest is the outlier, as it is a moving target.

However, cmake (3.22.2), has a mapping for 23 (and soon 26) to the best msvc match: c++latest. Those mapping choices are certainly debatable but are overridable in a defined way via CMAKE_CXX23_STANDARD_COMPILE_OPTION, so if clangd would accept the -std argument verbatim from compiler_commands.json when it's present, I think that would be more intuitive than the current behavior.

This still happens in clangd 16.0.0. Quite annoying, since Clangd otherwise requires zero configuration other than compiler_commands.json.