tornikeo
tornikeo

Reputation: 938

VScode C/C++ extension error when trying to assign a std::variant

I am using vscode with Microsoft C/C++ extension to analyze this C++ code:

#include <variant>

using namespace std;

int main() 
{
    variant<int, double> v;
    v = 12; //Marks as error 
    v = 12.0; //Marks as error
    //But compiles without errors.
}

The extension currently marks these lines as errors, but still can compile and run them with no problems.

To solve this, in tasks.json I added arguments like this:

...
"command": "/usr/bin/g++",
            "args": [
                "--std=c++17",
                "-pedantic-errors",
                ...
...

And in extension settings I explicitly set the C++ standard to C++17 and restarted.

But I still can't get rid of the red squiggles. On hover, the error says:

no operator "=" matches these operands -- operand types are: std::variant<int, double> = int

How do I fix this?

Edit: In my previous question, the vscode just wouldn't compile. Now it does, thanks to the edit in the extension settings. However, I still can't get rid of the red squiggles.

Upvotes: 1

Views: 478

Answers (1)

Mu00
Mu00

Reputation: 83

See https://github.com/microsoft/vscode-cpptools/issues/6623.

It only repros when clang is used (not gcc or cl.exe), changing your compilerPath to g++ may be a workaround.

Upvotes: 1

Related Questions