microsoft / vscode-cpptools

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

Setting c++ standard does not add -std argument to default build task #8070

Closed ghost closed 3 years ago

ghost commented 3 years ago

Bug type: Language Service

Describe the bug

Steps to reproduce

  1. Ctrl + Shift + P > C/C++: Edit Configurations (UI)
  2. Change C++ standard to c++20
  3. Create a main.cpp file in the folder
  4. Ctrl + Shift + P > Tasks: Configure Default Build Task > C/C++: g++ build active file (compiler = /usr/bin/g++)
  5. Note when tasks.json opens, the -std argument is missing under the args property
  6. Add some c++ code that uses a c++20 feature in main.cpp
  7. Ctrl + Shift + B
  8. Compiler error

Expected behavior

At step 5, there should be a -std argument in the args property of the task that is set to the c++ standard selected by the user. If none is selected through the UI, then it should match the default one that you can set through vscodes settings UI under extensions > C/C++. If that is not set, then it should use intellisense default standard.

Code sample and logs

int main() { char myString[]{ "string" }; const int length{ static_cast(std::size(myString)) }; // const int length{ sizeof(myString) / sizeof(myString[0]) }; // use instead if not C++17 capable std::cout << myString << " has " << length << " characters.\n";

for (int index{ 0 }; index < length; ++index)
    std::cout << static_cast<int>(myString[index]) << ' ';

std::cout << '\n';

return 0;

}

from https://www.learncpp.com/cpp-tutorial/c-style-strings/
- Configurations in `c_cpp_properties.json`
```json
{
    "configurations": [
        {
            "name": "Linux",
            "includePath": [
                "${workspaceFolder}/**"
            ],
            "defines": [],
            "compilerPath": "/usr/bin/g++",
            "cStandard": "gnu17",
            "intelliSenseMode": "linux-gcc-x64",
            "cppStandard": "c++20"
        }
    ],
    "version": 4
}

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


- Logs from [the language server logging](https://code.visualstudio.com/docs/cpp/enable-logging-cpp#_enable-logging-for-the-language-server)

**Screenshots**
<!-- If applicable, add screenshots to help explain your problem. -->

**Additional context**
<!--
Providing call stacks:
For bugs like crashes, deadlocks, infinite loops, etc. that we are not able to repro and for which the call stack may be useful, please attach a debugger and/or create a dmp and provide the call stacks. Windows binaries have symbols available in VS Code by setting your "symbolSearchPath" to "https://msdl.microsoft.com/download/symbols".

Instructions for attaching debugger to language service process:
https://github.com/microsoft/vscode-cpptools/wiki/Attaching-debugger-to-cpptools-or-cpptools%E2%80%90srv.

Performance analysis:
For a performance issue see instructions at https://github.com/microsoft/vscode-cpptools/wiki/Troubleshooting-Performance-Issues.
-->
sean-mcmanus commented 3 years ago

This is a duplicate of https://github.com/microsoft/vscode-cpptools/issues/7268 .