Hello,
I am new to Visual Studio, trying to migrate my projects in anticipation for the incoming C++20 support.
I work in MinGW / Cygwin environments, for which I am trying to set up an "open folder" development. So far I added corresponding CppProperties.json and tasks.vs.json files as described in open-folder-projects-cpp and using-mingw-and-cygwin-with-visual-cpp-and-open-folder and most things work.
However, I am having trouble with syntax errors for more up-to-date C++ standards. IntelliSense / parsing for C++11 seems to work fine (e.g. "auto i = 0;" shows no error), but I am getting syntax errors for C++17 constructs. E.g. the following show syntax errors:
if (int i = 0; i); // syntax error: "expected a ')'"
auto [i, j] = std::pair<int, int>{ 1,2 }; // syntax errors: "expected an identifier", "identifier "j" is undefined"
Here is most of (all the relevant parts) my CppProperties.json file for my MinGW setup:
{
"configurations": [
{
"inheritEnvironments": [
"Mingw64"
],
"name": "Mingw64",
"includePath ,": [
"${env.INCLUDE}",
"${workspaceRoot}\\include"
],
"defines": [
"__cplusplus=201709L"
],
"intelliSenseMode": "linux-gcc-x64",
"environments": [
{
"MINGW64_ROOT": "C:\\msys64\\mingw64",
"FLAVOR": "x86_64-w64-mingw32",
"TOOLSET_VERSION": "10.2.0",
"PATH": "${env.MINGW64_ROOT}\\bin;${env.MINGW64_ROOT}\\..\\usr\\bin;${env.PATH}",
"INCLUDE": "${env.MINGW64_ROOT}\\include\\c++\\${env.TOOLSET_VERSION};${env.MINGW64_ROOT}\\include\\c++\\${env.TOOLSET_VERSION}\\tr1;${env.MINGW64_ROOT}\\include\\c++\\${env.TOOLSET_VERSION}\\${env.FLAVOR};${env.MINGW64_ROOT}\\include;",
"environment": "Mingw64"
}
]
}
]
}
I also had to specifically add "__cplusplus=201709L" in order to e.g. use the <filesystem> header without errors. However, this did not fix syntax errors. I also tried to add ' "compilerSwitches": "-std=c++17" ', but this did not make a difference.
Hopefully this is possible somehow, since eliminating IDE syntax errors is a major reason I am trying to migrate to Visual Studio, as random incorrect syntax errors in my current IDE (Eclipse) are getting out of hand and I also cannot find any plans for C++20 support. So:
How do I correctly set the C++ standard in this case such that all syntax (including C++20 with the incoming Visual Studio 16.8?) is parsed correctly?