What Is a C++11 Extension [-Wc++11-Extensions]

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

Activate c++11 in your compiler option and the warning will disappear :)

It's just a "new" syntax, relative to the C++ 2011 norm, so unless you need backward compatibility with old compilers, you can safely enable c++11 support, or even c++14 or 17.


To configure Netbeans, I quote Ferenc Géczi's answer:

  1. Make sure that you have pointed NetBeans to the correct MinGW version.
    To do that, go to Project Properties > Build > Tool Collection > ... > Tool Collection Manager and
    there you can set the path to the proper g++ version.

  2. Make sure that you have set the correct compiler options:

    Project Properties > Build > C++ Compiler >

    Compilation Line > Additional Options

    set it to: -std=c++11

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.

warning: 'auto' type specifier is a C++11 extension [-Wc++11-extensions]

you want QMAKE_CXXFLAGS+=-Wno-c++11-extensions I suspect.

clang compiler documentation

pertinent part:

-Wfoo: Enable warning foo.

-Wno-foo: Disable warning foo.

warning: 'auto' type specifier is a C++11 extension

On MacOS, you're using clang, not gcc. (If I recall correctly, MacOS provides "gcc" and "g++" as symlinks to "clang" and "clang++", respectively, so that scripts that assume gcc don't break.)

The two compilers just treat this case differently.

Yes, a compiler that conforms to the 1998 ISO C standard, as both gcc and clang attempt to do with -std=c++98, must diagnose that line.

As far as the standard is concerned, a non-fatal warning is a valid diagnostic. The standard doesn't require an invalid program to be rejected (unless it contains a #error directive).

If you want to strictly enforce C++98 rules and reject code that violates them, use -std=c++98 -pedantic-errors (with either gcc or clang).

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.



Related Topics



Leave a reply



Submit