VS Code on macOS with cpptools 1.71.1+: When trying to compile code in C++, "-std=gnu++14" appears before all the flags. How to delete it?
Asked Answered
P

1

6

I am a beginner, using VSCode on macOS. Trying to iterate using square brackets which is requires C++17:

for (auto [document_id, relevance] : documents) {
            cout << "{ document_id = "s << document_id << ", relevance = "s << relevance << " }"s
                 << endl;
        }

When trying to Terminal -> Run build task, -std=gnu++14 flag appears before all other flags, even if -std=gnu++17 specified in tasks.json

Here are my tasks.json:

{
    "version": "2.0.0",
    "tasks": [
        {
            "type": "cppbuild",
            "label": "C/C++: clang++",
            "command": "/usr/bin/clang++",
            "args": [
                "-std=gnu++17",
                "-stdlib=libc++",
                "-fcolor-diagnostics",
                "-fansi-escape-codes",
                "-g",
                "${file}",
                "-o",
                "${fileDirname}/${fileBasenameNoExtension}"
            ],
            "options": {
                "cwd": "${fileDirname}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "detail": "/usr/bin/clang++"
        }
    ]
}

Here is the output:

 *  Executing task: C/C++: clang++ 

Starting build...
/usr/bin/clang++ -std=gnu++14 -std=gnu++17 -stdlib=libc++ -fcolor-diagnostics -fansi-escape-codes -g /Users/user/Documents/С++/000test/main.cpp -o /Users/user/Documents/С++/000test/main

Build finished successfully.
 *  Terminal will be reused by tasks, press any key to close it. 

What could be the problem?

I also tried to change the C++ version to 17 in the C/C++ extension, but to no avail.

When running with "-std=gnu++17", "-stdlib=libc++" in tasks json no warning appears, but does the second -std flag override the first one?

I also found this topic, but I dont even have CMake extension in vscode.

Pyrochemical answered 16/9, 2023 at 19:34 Comment(7)
Apologies for asking the obvious, but you did save the files after editing right? It seems fairly common for folks using VSCode to forget that.Stylite
Are you maybe using code runner?Gestate
@RetiredNinja Yes, both files saved, even tried to close and run vscode before running a program againPyrochemical
@AlanBirtles Its C/C++ extension package from which I deleted CMake just in case, since I don't need it right now. No code runner installed. Code is running fine with -std=gnu++17 in tasks.jsonPyrochemical
@273K Thank you for correcting me and I apologize if I did not describe something clearly. Added output. I'm running "C/C++: clang++" taskPyrochemical
/usr/bin/clang++ in the terminal looks like an alias for /usr/bin/clang++ -std=gnu++14.Outrageous
what is "Terminal -> Run Build Task"? How exactly do you invoke that action?Misguided
G
7

Looks like this is hard coded into the c++ extension:

https://github.com/microsoft/vscode-cpptools/blob/dec50598bc4d169b38292d2f4ff26a216d3c6342/Extension/src/LanguageServer/cppBuildTaskProvider.ts#L370

insertStd is set to true for clang on macos.

I'd raise a bug with Microsoft but in the meantime just don't build directly with tasks, use cmake or another build system and you'll avoid this problem.

This was added recently: https://github.com/microsoft/vscode-cpptools/pull/11300

Gestate answered 17/9, 2023 at 5:50 Comment(4)
See also #40563769Gestate
Hold up, what's the trigger here? "command" == clang++? That PR thread looks like it should only trigger when you're building a file without tasks.json...Anthracnose
@Anthracnose i think it's for the default generated task that you get when you to to build the active file, not sure how it works, I've only ever used cmakeGestate
@AlanBirtles Thank you! I downgraded the C/C++ extension and that solved the problem.Pyrochemical

© 2022 - 2024 — McMap. All rights reserved.