microsoft / vscode-cpptools

Official repository for the Microsoft C/C++ extension for VS Code.
Other
5.51k stars 1.55k forks source link

Extension overrides C/C++ standard settings from configuration #12451

Open AstralStorm opened 3 months ago

AstralStorm commented 3 months ago

Environment

Bug Summary and Steps to Reproduce

Bug Summary: Due to current automatic behavior, it is impossible to use intellisense with cl.exe on older projects that correctly compile with CL. Extension always overrides cStandard and cppStandard settings based on compiler path for cl.exe if flags are given without /std. The default settings without flags are C89 and C++14 - at least for Visual Studio 2022 CL 19.40.33811. There is no /std flag for standards older than C11 and C++14, but the compiler accepts these without a flag.

Steps to reproduce:

  1. Create c_cpp_properties.json with selected cStandard and cppStandard older than C++17/C17.
  2. Note messages like: For C++ source files, the cppStandard was changed from "c++03" to "c++17" based on compiler args and querying compilerPath For C source files, the cStandard was changed from "c89" to "c17" based on compiler args and querying compilerPath

Expected behavior: If any of /permissive, /Zc or /Ze are provided in arguments, the override is not applied. OPTIONALLY: Plugin checks the compiler version by running cl.exe and sets the override based on compiler version. This would typically be C89/C++14, unless it changes later for a newer Microsoft compiler.

Configuration and Logs

{
    "configurations": [
        {
            "name": "C89/C++03 VS2022",
            "intelliSenseMode": "windows-msvc-x64",
            "compilerPath": "C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Tools\\MSVC\\14.40.33807\\bin\\Hostx64\\x64\\cl.exe",
            "compilerArgs": [
                "/Od",
                "/permissive"
            ],
            "cppStandard": "c++03",
            "cStandard": "c89",
            "windowsSdkVersion": "10.0.19041.0"
        }
    ],
    "version": 4
}

Other Extensions

No response

Additional context

No response

sean-mcmanus commented 2 months ago

The C++ version defaulting to C++17 instead of C++14 was a regression starting with 1.19.5. We have never supported IntelliSense without a std, but it looks like that is easy to add.