How to choose C++ standard in "Open folder" development (linux-gcc mode)

CR 136 Reputation points
2020-10-30T19:40:47.363+00:00

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?

C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,764 questions
0 comments No comments
{count} votes

Accepted answer
  1. Jeanine Zhang-MSFT 9,866 Reputation points Microsoft Vendor
    2020-11-02T03:04:38.983+00:00

    Hi,

    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?

    I suggest you could try to use "compilerSwitches": "/std:c++latest"

    Best Regards,

    Jeanine


    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.