G ++ compiling C ++ 11 with -Wpedantic options: is it possible to disable only the warning of unnamed structures?

I want to save any other -Wpedantic checks, but lose the warning about unnamed error: ISO C++ prohibits anonymous structs [-Wpedantic] structures error: ISO C++ prohibits anonymous structs [-Wpedantic] .

I want to be able to do the following:

 union { struct { float x, y, z, w; }; struct { float r, g, b, a; }; float v[4]; }; 

What i have found so far

I'm using C ++ 11 and compiled with the flag -std=c++11 . I read that C11 supports this function , but I did not see mention that it is supported in C ++ 11.

I came across the mention of -fms-extensions :

I tried the flag and it seems to have no effect (regardless of the rearrangement of the order between -fms-extensions and -Wpedantic ).

EDIT - More Info

Thanks to the comments, I found the following:

  • Information on why unnamed classes / structures do not fully comply with the standard

  • A message that says that my sample code depends on undefined behavior

I would still like to know if there is a way to enable this gcc extension (which all compilers know to me) will turn off the warning. Or -Wpedantic all or nothing?

+7
c ++ gcc c ++ 11
source share
1 answer

You can temporarily disable -Wpedantic , for example, if you have old code in a file include:

 #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wpedantic" #include "old_header.hpp" #pragma GCC diagnostic pop 

Of course, you can also do this in every case, when you use an anonymous structure to limit the area in which the pedantic disabled, but when you do, you can just go ahead and fix the code itself:)

+3
source share

All Articles