In C++11 I declare the following union:
union U4 {
char c;
int i;
static int si;
};
When I compile this code with g++ 4.7.0 using -std=c++11 -pedantic-errors, I get the following errors (with minor editing):
error: local class ‘union U4’ shall not have static data member ‘int U4::si’ [-fpermissive]
error: ‘U4::si’ may not be static because it is a member of a union
The FDIS (N3242) does not explicitly allow static data members of named unions, as far as I can see. But I also don't see where the FDIS disallows static data members of named unions either The FDIS does repeatedly refer to what can be done with "non-static data members" [section 9.5 paragraph 1]. By contrast, that suggests the standard permits static data members of unions.
I don't have any use in mind for a static data member of a union. If I needed it I could probably get a close enough effect with a class containing an anonymous union. I'm just trying to understand the intent of the standard.
Thanks for the help.
§9.4.2/5
), so that's where your first error comes from. For static data member in a non-localunion
Clang compiles just fine. – Xeo