Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
alligatorjazz opened this issue May 3, 2024 · 6 comments
Open

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

alligatorjazz opened this issue May 3, 2024 · 6 comments
Assignees
Labels
more info needed The issue report is not actionable in its current state tasks/build/debug An issue relating to tasks.json (e.g. build issues)

Comments

@alligatorjazz
Copy link

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.

@bobbrow
Copy link
Member

bobbrow commented May 3, 2024

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

@alligatorjazz
Copy link
Author

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).

@sean-mcmanus
Copy link
Collaborator

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

@sean-mcmanus
Copy link
Collaborator

sean-mcmanus commented May 4, 2024

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

@sean-mcmanus
Copy link
Collaborator

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

@sean-mcmanus
Copy link
Collaborator

sean-mcmanus commented May 4, 2024

@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.

@sean-mcmanus sean-mcmanus self-assigned this May 4, 2024
@sean-mcmanus sean-mcmanus added more info needed The issue report is not actionable in its current state tasks/build/debug An issue relating to tasks.json (e.g. build issues) labels May 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
more info needed The issue report is not actionable in its current state tasks/build/debug An issue relating to tasks.json (e.g. build issues)
Projects
None yet
Development

No branches or pull requests

3 participants