vscode-cpptools icon indicating copy to clipboard operation
vscode-cpptools copied to clipboard

Extension overrides C/C++ standard settings from configuration

Open AstralStorm opened this issue 1 year ago • 1 comments

Environment

  • OS and Version: Windows 10 22H2
  • VS Code Version: 1.91.0
  • C/C++ Extension Version: 1.20.5

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

AstralStorm avatar Jul 07 '24 03:07 AstralStorm

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.

sean-mcmanus avatar Jul 08 '24 19:07 sean-mcmanus