Visual Studio Code C++11 Extension Warning

How to remove the C++ 11 extension warning in the vsCode

You will have to edit the c_cpp_properties.json file. See an example of it here.

{
"env": {
"myDefaultIncludePath": ["${workspaceFolder}", "${workspaceFolder}/include"],
"myCompilerPath": "/usr/local/bin/gcc-7"
},
"configurations": [
{
"name": "Mac",
"intelliSenseMode": "clang-x64",
"includePath": ["${myDefaultIncludePath}", "/another/path"],
"macFrameworkPath": ["/System/Library/Frameworks"],
"defines": ["FOO", "BAR=100"],
"forcedInclude": ["${workspaceFolder}/include/config.h"],
"compilerPath": "/usr/bin/clang",
"cStandard": "c11",
"cppStandard": "c++17",
"compileCommands": "/path/to/compile_commands.json",
"browse": {
"path": ["${workspaceFolder}"],
"limitSymbolsToIncludedHeaders": true,
"databaseFilename": ""
}
}
],
"version": 4
}

In that file an option cppStandard is listed. It has to be set to c++11. Then auto will be supported.

Visual Studio Code: code not running for C++11

Build

clang will need the -std=c++11 option. Clang c++11

g++ will accept -std=c++11 or -std=gnu++11 Gnu C++ standards support

Executing test()

You will need to call function test within main for the test to execute.

int main()
{
test();
}

Note:

I use cmake with a CMakeLists.txt to build my projects.

Compile error on vscode. type specifier is a C++11 extension

Sounds like an old version of gcc. You should upgrade!

You can get this to work by changing

"args": ["-O2", "-g", "test.cpp"],

to

"args": ["-std=c++11", "-O2", "-g", "test.cpp"],

but, really, consider upgrading.

Reference: https://gcc.gnu.org/gcc-4.8/cxx0x_status.html

What is the meaning of range-based for loop is a C++11 extension and what is expected expression?

warning: range-based for loop is a C++11 extension [-Wc++11-extensions]

What this means is that you are compiling your code with a version of C++ selected that is prior to C++11, but as an extension, your compiler is going to allow you to do it anyway. However, the code is not portable because not all compilers will allow it. That is why it is warning you.

If you want your code to be portable, you should either stop using the range-based-for, or compile with the C++11 version (or greater) of the C++ Standard selected.

This may mean adding a flag like -std=c++11 to your compile command, but it varies by compiler and development environment.

I would also advise configuring your compiler to adhere to strict standards if you want portable code. For example, with GCC or clang this can be done by adding -pedantic-errors to the compile command.



Related Topics



Leave a reply



Submit