Skip to content

Incorrect C++ standard given while present in compile_commands.json #13405

@BluTree

Description

@BluTree

Environment

  • OS and Version: 26100.3476
  • VS Code Version: 1.98.2
  • C/C++ Extension Version: 1.24.3 (but bug reproduced in 1.24.2 also)

Bug Summary and Steps to Reproduce

Bug Summary:
The extension fails to set the correct C++ standard, while the file is correctly found in compile_commands.json. In my case, the extension gives the C++17 standard while I'm specifying the C++20 standard.

Steps to reproduce:

  1. Write this snippet of code in test.cc:
#include <concepts>

template <typename T>
	requires std::same_as<T, int>
void func(T);

int main(int argc, char** argv)
{
	#ifdef TEST_DEFINE
	func(TEST_DEFINE);
	#endif
	func(1);
	return 0;
}
  1. Write a compile_commands.json with this entry:
[
	{
		"directory": "./",
		"command": "clang++ -g -Wall -std=c++20 -DTEST_DEFINE=3",
		"file": "test.cc"
	}
]
  1. Setup the compile command in the c_cpp_properties.json
  2. Notice the errors on the require keyword, while the TEST_DEFINE define is correctly given

Expected behavior:
The extension should correctly find all the options given to the compiler in compile_commands

On a side note, when I was looking for help in the logs, I noticed this strange error:
Specified compiler was not found: c:\Dev\Sources\C++ tests\clang++ (with c:\Dev\Sources\C++ tests\ being the workspace folder)

This error doesn't appear when running with 1.24.1 version

Configuration and Logs

-------- Diagnostics - 3/22/2025, 11:11:59 PM
Version: 1.24.3
Current Configuration:
{
    "name": "Win32",
    "intelliSenseMode": "windows-clang-x64",
    "compileCommands": [
        "c:\\Dev\\Sources\\C++ tests\\compile_commands.json"
    ],
    "compilerPathIsExplicit": false,
    "cStandardIsExplicit": false,
    "cppStandardIsExplicit": true,
    "intelliSenseModeIsExplicit": true,
    "compileCommandsInCppPropertiesJson": [
        "compile_commands.json"
    ],
    "cppStandard": "c++17",
    "mergeConfigurations": false,
    "browse": {
        "limitSymbolsToIncludedHeaders": true
    }
}
Modified Settings:
{
    "C_Cpp.default.compilerPath": "C:\\Dev\\LLVM\\bin\\clang++.exe",
    "C_Cpp.default.cppStandard": "c++17",
    "C_Cpp.exclusionPolicy": "checkFilesAndFolders",
    "C_Cpp.formatting": "clangFormat",
    "C_Cpp.doxygen.generateOnType": false,
    "C_Cpp.codeAnalysis.exclude": {
        "folder": true
    },
    "C_Cpp.codeAnalysis.clangTidy.enabled": true,
    "C_Cpp.codeAnalysis.clangTidy.path": "C:\\Dev\\LLVM\\bin\\clang-tidy.exe",
    "C_Cpp.intelliSenseMemoryLimit": 16384,
    "C_Cpp.loggingLevel": "Debug",
    "C_Cpp.experimentalFeatures": "enabled",
    "C_Cpp.caseSensitiveFileSupport": "enabled"
}
Additional Tracked Settings:
{
    "editorTabSize": 4,
    "editorInsertSpaces": false,
    "editorAutoClosingBrackets": "languageDefined",
    "filesEncoding": "utf8",
    "filesAssociations": {
        "*.sln": "xml",
        "log": "log",
        "vector": "cpp",
        "concepts": "cpp"
    },
    "filesExclude": {
        "**/.git": true,
        "**/.svn": true,
        "**/.hg": true,
        "**/.DS_Store": true,
        "**/Thumbs.db": true
    },
    "filesAutoSaveAfterDelay": false,
    "editorInlayHintsEnabled": true,
    "editorParameterHintsEnabled": true,
    "searchExclude": {
        "**/node_modules": true,
        "**/bower_components": true,
        "**/*.code-search": true
    },
    "workbenchSettingsEditor": "ui"
}
cpptools version (native): 1.24.3.0
Current database path: C:\Users\Aubin\AppData\Local\Microsoft\vscode-cpptools\2e0838e3c682a3a1661b48151af947ff\.browse.VC.db
Translation Unit Mappings:
[ C:\Dev\Sources\C++ tests\test.cc - source TU]:
Translation Unit Configurations:
[ C:\Dev\Sources\C++ tests\test.cc ]
    Process ID: 18908
    Memory Usage: 61 MB
    Compiler Path: C:\Dev\LLVM\bin\clang.exe
    Include paths:
        system include: C:\Dev\LLVM\lib\clang\19\include
        system include: C:\Dev\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.41.34120\include
        system include: C:\Dev\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.41.34120\atlmfc\include
        system include: C:\Windows Kits\10\Include\10.0.22621.0\ucrt
        system include: C:\Windows Kits\10\Include\10.0.22621.0\shared
        system include: C:\Windows Kits\10\Include\10.0.22621.0\um
        system include: C:\Windows Kits\10\Include\10.0.22621.0\winrt
        system include: C:\Windows Kits\10\Include\10.0.22621.0\cppwinrt
    Defines:
        TEST_DEFINE=3
    Standard Version: c++17
    IntelliSense Mode: windows-clang-x64
    Other Flags:
        --clang
        --clang_version=190103
        --ms_compatibility
    compile_commands.json entry:
        directory: c:\Dev\Sources\C++ tests\
        file: C:\Dev\Sources\C++ tests\test.cc
        command: clang++ -g -Wall -std=c++20 -DTEST_DEFINE=3
Total Memory Usage: 61 MB
Browse Paths from compile_commands.json, from workspace folder: C:\Dev\Sources\C++ tests
    C:\Dev\LLVM\lib\clang\19\include
    C:\Dev\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.41.34120\atlmfc\include
    C:\Dev\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.41.34120\include
    C:\Dev\Sources\C++ tests
    C:\Windows Kits\10\Include\10.0.22621.0\cppwinrt
    C:\Windows Kits\10\Include\10.0.22621.0\shared
    C:\Windows Kits\10\Include\10.0.22621.0\ucrt
    C:\Windows Kits\10\Include\10.0.22621.0\um
    C:\Windows Kits\10\Include\10.0.22621.0\winrt
    C:\Dev\Sources\C++ tests

------- Workspace parsing diagnostics -------
Number of files discovered (not excluded): 5387

Other Extensions

No response

Additional context

No response

Metadata

Metadata

Assignees

Labels

bugfixedCheck the Milestone for the release in which the fix is or will be available.insidersCurrently only repros with our latest Insiders release.regressionA bug that didn't exist in a previous release

Type

Projects

Status

Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions