-std=c++11 flag unrecognized in gcc/g++ 4.4.6 - c++

I have some code written using the C++11 standards, and our g++ version is 4.4.6, so as far as I can tell, C++11 should be supported (from 4.3 onwards).
However upon trying to compile with the flags -std=c++11 -std=gnu++11, I get repetitions of the errors
cc1plus: error: unrecognized command line option `-std=c++11`
cc1plus: error: unrecognized command line option `-std=gnu++11`
Compiling with -std=c++0x produces errors such as
DeviceInfo.cpp:22: error: expected initializer before ‘:’ token
corresponding to this line of code:
for (cl::Platform& plat : platforms)
Is this a C++11 specific bit of Syntax? (it doesn't look like it to me, but all this code has been given as an example so should work as provided with the compiler.)
Any help?

-std=c++11 setting is supported by much later versions of GCC. The initial support for nascent C++11 was enabled by -std=c++0x setting. This is probably what you should try.
And yes, the for syntax you are trying to use is chiefly C++11 syntax.

It appears as if range-based for loops are supported in 4.6 and newer.
This page shows GCC support for C++11 features.

for (cl::Platform& plat : platforms)
Yes, it is C++11 specific usage. GCC 4.7 or later supports C++11 with -std=c++11 option meanwhile.

Related

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

I have a very simple C++ code statement auto a = 12;.
When I am compiling it with g++ in Linux using -std=c++98 option I am getting an error as expected
error: ‘a’ does not name a type
But when I am compiling the same code with the same option in MacOS I am getting just a warning, but the code get's compiled fine.
warning: 'auto' type specifier is a C++11 extension [-Wc++11-extensions]
But wasn't the whole point of -std=c++98 to compile the code following C++ 98 standards? So the warning tells even though auto is a C++11 extension I am going to compile it for you?
Is there any option to force using c++98 (or other standard)?
g++ --version prints
Apple clang version 12.0.0 (clang-1200.0.32.29)
which is another weird thing by the way. So it is clang actually.
It's like asking firefox --version and getting chrome 87.0.4280.163
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).
You may be looking for -pedantic or -pedantic-errors, quoting man g++:
-pedantic
Issue all the warnings demanded by strict ISO C and ISO C ++ ; reject all programs that use forbidden extensions, and some other
programs that do not follow ISO C and ISO C ++ . For ISO C, follows
the version of the ISO C standard specified by any -std option used.
Note: this is not meant as a feature to check strict standards conformance (see the rest of the description in the man page)

ISO C++ forbids declaration of .. with no type with --std=c++0x set

In my c++ code I'm using the auto type, to enable c++11, I add the flag --std=c++0x to my makefile, but I still get error of ISO C++ forbids declaration of .. with no type, if I enable c++11 with -std=gnu++11 or -std=c++11, I got cc1plus: error: unrecognized command line option "...", my gcc version is 4.3.4, how should I solve this? Thank you.
Without enabling c++11, I got error of ISO C++ forbids declaration of wallclock with no type the following line:
auto wallclock = time(nullptr);
Support for auto-typed variables was not implemented in GCC before version 4.4. The version you are using is too old.
See support matrix: https://gcc.gnu.org/projects/cxx0x.html

C++11 string properties and gcc version

I currently use C++ string properties and specifically its pop_back() fonction. As written in the title, it leads to an error (same error seen ini an other topic) :
‘std::string’ has no member named ‘pop_back’
But what's strange is that I already use C++11 specific properties (as "auto" for iterators, etc.) and I never get any error.
For information, I build my code under Ubuntu 12.04 with gcc 4.6.3. For me, this version is good enough. I also put "-std=c++0x" flag so I really don't know where is the point ?!
Moreover, I've seen, in previous topic, that it's better to use "-std=c++11" flag now. But when I try this, the following error appears :
unrecognized command line option ‘-std=c++11’
On gcc 4.6 (which had only partial support for the new standard) the option is -std=c++0x because at that time the release date (i.e., 2011) was still unknown.

Compile with Intel 12.1.3 using gcc4.7 std library

I'm having the same problem described in this post except I'm using Intel version 12.1.3. (g++'s header <functional> is protected with #ifdef __GXX_EXPERIMENTAL_CXX0X__ which is not defined when icpc is used.)
Instead of using boost::functional, I wanted to install gcc4.7 and use it's std libraries.
In Ubuntu 11.10 I have gcc4.6.1 but I also installed gcc4.7 from the gcc-snapshot package.
Intel has the options -gcc-name, -gxx-name, and -cxxlib.
So originally I compiled with:
-std=c++0x -gcc-name=/usr/lib/gcc-snapshot/bin/gcc -gxx-name=/usr/lib/gcc-snapshot/bin/g++ -cxxlib=/usr/lib/gcc-snapshot/
but I get the error:
icpc: error #10282: file
'/usr/lib/gcc-snapshot/bin/usr/lib/gcc-snapshot/bin/g++' not found,
generated based on '-cxxlib=/usr/lib/gcc-snapshot/'
So then I compiled with:
-std=c++0x -gcc-name=./gcc -gxx-name=./g++ -cxxlib=/usr/lib/gcc-snapshot/.
But I still get the warnings and errors:
Warning #2928: the __GXX_EXPERIMENTAL_CXX0X__ macro is disabled when using GNU version 4.6 with the c++0x option
error: namespace "std" has no member "function"
The warning clearly says it's still using version 4.6. Does anybody know how to get Intel to use the correct libraries?
I've found that if you compile with gcc (or g++) with flags -v -Q you get a list of flags and defines. It might help you see what gcc does so maybe you can use the same -D/-U in icpc. also g++ -E will preprocess without compiling: you can get useful path information from that.

How does one suppress specific warnings from source code on g++ 4.5 or later?

The first comment on a feature request for g++ says, "Starting with 4.5 you can disable a class of warnings in the source."
I looked through the 4.5.0 manual, but I can't find the syntax.
What is the syntax in g++ 4.5 and later to suppress individual warning classes in the source?
http://gcc.gnu.org/onlinedocs/gcc/Pragmas.html
http://gcc.gnu.org/onlinedocs/gcc/Diagnostic-Pragmas.html#Diagnostic-Pragmas