0

I'm trying to set up VS Code to learn C++. I downloaded the latest version of the compiler (g++) and tried running the following simple code, which (if I understand this correctly) should print a "conversion from double to float" warning:

int main(){
    float f{4.1};
    return 0;
}

However everything goes absolutely smooth and nothing gets printed. When I try to compile this directly through the terminal, I use the following command g++ -Wconversion myfile.cpp, the compiler goes through and the warning pops up. So I guess this is a VS Code problem. I tried going through the tasks.json file and adding the options to show warnings, and now it looks like this

{
    "tasks": [
        {
            "type": "cppbuild",
            "label": "C/C++: g++.exe build active file",
            "command": "C:\\msys64\\mingw64\\bin\\g++.exe",
            "args": [
                "-fdiagnostics-color=always",
                "-g",
                "${file}",
                "-o",
                "${fileDirname}\\${fileBasenameNoExtension}.exe",
                "-Wall",
                "-Weffc++",
                "-Wextra",
                "-Wconversion",
                "-Wsign-conversion",
            ],
            "options": {
                "cwd": "C:\\msys64\\mingw64\\bin"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "detail": "Task generated by Debugger."
        }
    ],
    "version": "2.0.0"
}

but this seems to be doing nothing.

2
  • Are you sure your tasks.json is being used? vscode will ignore it if it's not at the right place, or if your launch.json doesn't spell the task name exactly. I also recommend adding -Werror --- you do not want to run your program if it compiles with warnings. Commented Oct 12 at 22:23
  • can you please provide info on what happens when you run your task? what do you see in the task output? Commented Oct 15 at 20:44

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.