microsoft / vscode-cpptools

Official repository for the Microsoft C/C++ extension for VS Code.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

vscode c++ debug refuses to respect c++ standard

alligatorjazz opened this issue · comments

Environment

  • OS and version: MacOS Sonoma 14.0
  • VS Code: 1.88.1
  • C/C++ extension: v1.20.4
  • OS and version of remote machine (if applicable): N/A
  • GDB / LLDB version: lldb-1500.0.21.4

Bug Summary and Steps to Reproduce

Bug Summary:
"C/C++ Run C/C++ File" includes an argument that sets the C++ standard to "gnu++14", even after setting it to "c++20" in the extension settings and task arguments.

Steps to reproduce:

  1. Create a new C++ project with the "Cpp Standard" set to c++20 in the extension settings.
  2. Add "--std=c++20" to the tasks.json arguments array.
  3. Try to run a file with c++20 features (in my case, the main file repo linked here where i try to use std::format)
  4. The task will throw the following error:
*  Executing task: C/C++: clang build active file 

Starting build...
/usr/bin/clang -std=gnu++14 --std=c++20 -fcolor-diagnostics -fansi-escape-codes -g /Users/bright-silicon/lab/tictac-online/main.cpp -o /Users/bright-silicon/lab/tictac-online/main
/Users/bright-silicon/lab/tictac-online/main.cpp:30:21: error: no member named 'format' in namespace 'std'
                std::cout << std::format(" {} | ", c + 1);
                             ~~~~~^
/Users/bright-silicon/lab/tictac-online/main.cpp:33:22: error: no member named 'format' in namespace 'std'
                        std::cout << std::format("{} |", board[c * r]);
                                     ~~~~~^
2 errors generated.

Build finished with error(s).

Debugger Configurations

// tasks.json
{
    "tasks": [
        {
            "type": "cppbuild",
            "label": "C/C++: clang build active file",
            "command": "/usr/bin/clang",
            "args": [
				"--std=c++20",
                "-fcolor-diagnostics",
                "-fansi-escape-codes",
                "-g",
                "${file}",
                "-o",
                "${fileDirname}/${fileBasenameNoExtension}"
            ],
            "options": {
                "cwd": "${fileDirname}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "detail": "Task generated by Debugger."
        }
    ],
    "version": "2.0.0"
}

```json
// launch.json{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "C/C++: clang build and debug active file",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}/${fileBasenameNoExtension}",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${fileDirname}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "lldb",
            "preLaunchTask": "C/C++: clang build active file"
        }
    ]
}


### Debugger Logs

```shell
*  Executing task: C/C++: clang build active file 

Starting build...
/usr/bin/clang -std=gnu++14 --std=c++20 -fcolor-diagnostics -fansi-escape-codes -g /Users/bright-silicon/lab/tictac-online/main.cpp -o /Users/bright-silicon/lab/tictac-online/main
/Users/bright-silicon/lab/tictac-online/main.cpp:30:21: error: no member named 'format' in namespace 'std'
                std::cout << std::format(" {} | ", c + 1);
                             ~~~~~^
/Users/bright-silicon/lab/tictac-online/main.cpp:33:22: error: no member named 'format' in namespace 'std'
                        std::cout << std::format("{} |", board[c * r]);
                                     ~~~~~^
2 errors generated.

Build finished with error(s).

Other Extensions

No response

Additional Information

No clue how to tackle this further - every guide either told me to change the standard in the extension settings or add c++20 to the clang arguments, neither of which remove the initial -std=gnu++14 argument which seems to be added automatically and separately from the arguments in the tasks.json. The actual repo I am having issues with is linked here.

It looks like you might have an extra hyphen in your command argument. Can you try -std=c++20 instead of --std=c++20?

It looks like you might have an extra hyphen in your command argument. Can you try -std=c++20 instead of --std=c++20?

Tried that, exactly the same result. Still doesn't remove the initial -std=gnu++14.

Starting build...
/usr/bin/clang -std=gnu++14 -std=c++20 -fcolor-diagnostics -fansi-escape-codes -g /Users/bright-silicon/lab/tictac-online/main.cpp -o /Users/bright-silicon/lab/tictac-online/main
/Users/bright-silicon/lab/tictac-online/main.cpp:30:21: error: no member named 'format' in namespace 'std'
                std::cout << std::format(" {} | ", c + 1);
                             ~~~~~^
/Users/bright-silicon/lab/tictac-online/main.cpp:33:22: error: no member named 'format' in namespace 'std'
                        std::cout << std::format("{} |", board[c * r]);
                                     ~~~~~^
2 errors generated.

Build finished with error(s).

@alligatorjazz A 2nd -std should replace any earlier ones (it does for me).

@alligatorjazz Are you #including the header? UPDATE: I found your example code (you are including it).

@alligatorjazz Are you using clang version 17 or newer? It was only taken out of experimental with that version.

@alligatorjazz The Apple clang that comes with Mac is still LLVM version 16. You could try adding arg -fexperimental-library to see if that works.

This issue has been closed because it needs more information and has not had recent activity.