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

Default cppbuild task doesn't have C/C++ standard flag #7268

Closed
longnguyen2004 opened this issue Apr 1, 2021 · 9 comments
Closed

Default cppbuild task doesn't have C/C++ standard flag #7268

longnguyen2004 opened this issue Apr 1, 2021 · 9 comments
Assignees
Labels
bug duplicate Language Service tasks/build/debug An issue relating to tasks.json (e.g. build issues)

Comments

@longnguyen2004
Copy link

VS Code version: 1.54.3
Extension version: 1.3.0-insiders2

I don't really know where to put this, please tell me if this issue should be moved.

The default cppbuild task doesn't add a C/C++ standard flag when an explicit standard is set in the compiler configurations. It should be added automatically to prevent confusion.

Build output:

> Executing task: C/C++: clang-12.exe build active file <

Starting build...
C:\llvm-mingw\bin\clang-12.exe -g [REDACTED] -o [REDACTED] -glldb -lc++ -lunwind -IC:\vcpkg\installed\x64-mingw-dynamic\include -LC:\vcpkg\installed\x64-mingw-dynamic\lib -lcpr -lcurl
Build finished successfully.

(Notice there's no -std=... flag)

My compiler configuration:

{
    "configurations": [
        {
            "name": "llvm-mingw",
            "includePath": [
                "${workspaceFolder}/**",
                "C:\\vcpkg\\installed\\x64-mingw-dynamic\\include"
            ],
            "defines": [
                "_DEBUG"
            ],
            "compilerPath": "C:\\llvm-mingw\\bin\\clang-12.exe",
            "cStandard": "c17",
            "cppStandard": "c++17",
            "intelliSenseMode": "windows-clang-x64",
            "compilerArgs": [
                "-glldb",
                "-lc++",
                "-lunwind",
                "-IC:\\vcpkg\\installed\\x64-mingw-dynamic\\include",
                "-LC:\\vcpkg\\installed\\x64-mingw-dynamic\\lib",
                "-lcpr",
                "-lcurl"
            ]
        }
    ]
}

(cStandard and cppStandard are set explicitly)

@sean-mcmanus
Copy link
Collaborator

What is your tasks.json? The tasks.json is where the build flags are set. The compilerArgs in c_cpp_properties.json are separate and only used for IntelliSense.

@sean-mcmanus sean-mcmanus self-assigned this Apr 1, 2021
@sean-mcmanus sean-mcmanus added tasks/build/debug An issue relating to tasks.json (e.g. build issues) Language Service more info needed The issue report is not actionable in its current state labels Apr 1, 2021
@longnguyen2004
Copy link
Author

I don't have a tasks.json, since I don't want to duplicate the settings between two files. If it's not possible to add the flag to the pre-provided task, is there a way to get the currently set standard, through command substitution?

@sean-mcmanus
Copy link
Collaborator

sean-mcmanus commented Apr 1, 2021

Okay, I see, you're using the Run: Build Task (without an existing tasks.json). Normally, I use F5, Build and Debug Active File, or Configure Default Build Task, which generates the tasks.json.

The scenario you're hitting where it uses the compilerArgs from c_cpp_properties.json seems like a corner case that I wasn't even aware of, and it doesn't seem like the scenario was fully developed (i.e. the cppStandard not being used).

Adding a -std= compilerArg should be a workaround.

@sean-mcmanus sean-mcmanus added bug and removed more info needed The issue report is not actionable in its current state labels Apr 1, 2021
@sean-mcmanus sean-mcmanus removed their assignment Apr 1, 2021
@longnguyen2004
Copy link
Author

Unfortunately I'm using Clang, and it doesn't like the -std=c++17 flag when invoked with -x c during the compiler probe, so it'll fail.

I can workaround this with a tasks.json, but not having to update 2 files to change the standard is definitely better.

@sean-mcmanus
Copy link
Collaborator

Ah, I see, I've filed bug #7269 .

Another (more complicated) alternative is to switch Makefile or CMake to build and set Makefile/CMake Tools as the configurationProvider, in which case the build and IntelliSense configurations will be shared.

We have a related issue tracking propogating c_cpp_properties.json settings to tasks.json #6080 .

@bobbrow
Copy link
Member

bobbrow commented Apr 20, 2021

Ok, just to make sure we understand the action item for this issue, this is what we're planning to do:

  • add the cppStandard or cStandard into the compile command for the file (assuming we can get the file type before the task provider executes)

@bobbrow bobbrow added this to the On Deck milestone Apr 20, 2021
@longnguyen2004
Copy link
Author

Yes that is what I want to see.

@sean-mcmanus
Copy link
Collaborator

The issue blocking usage of -std=c++17 is fixed with https://github.com/microsoft/vscode-cpptools/releases/tag/1.4.0-insiders

@bobbrow
Copy link
Member

bobbrow commented Mar 8, 2022

I think the way to go here is to add a feature to tasks that allows us to pull all the information from c_cpp_properties.json (or the current configuration) so that people don't have to add it in both places. We have a request tracking this here: #1285. I will dupe this issue to that one.

@bobbrow bobbrow closed this as completed Mar 8, 2022
@github-actions github-actions bot locked and limited conversation to collaborators Apr 23, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug duplicate Language Service tasks/build/debug An issue relating to tasks.json (e.g. build issues)
Projects
None yet
Development

No branches or pull requests

5 participants