Regarding standards, anonymous structures are a function of C. They are not allowed by any C ++ standard.
I could not find the detailed gcc documentation about my extension to provide this function in C ++. What I found is here , but this page only describes the extension for C (prior to C11 this function was not standard).
My question is: if the POD type is actually insufficient for an anonymous structure,
It really seems insufficient. The error message clearly explains that having a (non-trivial) constructor disqualifies the class as an anonymous aggregate (structure). POD would guarantee this only until C ++ 11.
Since there is little documentation for the extension, and since anonymous structures are a function of C, I am tempted to assume that any such aggregate should not use the capabilities of C ++. I believe that the definition of POD for pre-C ++ 11 satisfies this requirement.
A quick test seems to be consistent with my hypothesis. If you remove the constructor, the program compiles with the extension enabled. If you name a member of the structure (a promotion type that needs to be anonymous), the program will be well formed by standard C ++, and also compiled.
Or maybe, since GCC is different from all other compilers, is this a problem with GCC?
Since they implemented them, it is possible that this is not a problem with them. This can be a problem for those who want to compile without modification, a non-standard program written for another compiler. This is a problem with non-standard language features.
source share