http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53524
Lawrence Crowl <crowl at google dot com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |crowl at google dot com --- Comment #3 from Lawrence Crowl <crowl at google dot com> 2012-05-30 04:24:24 UTC --- I believe the code is well-formed. The enum in the PointerUnionUIntTraits declaration is a plain enum, so the underlying type is not fixed. For enums where the underlying type is not fixed, the underlying type of each enumerator is determined by its initializing expression, not by the underlying type of the enumeration as a whole, until the enumeration is complete. So, the underlying type of each enum value is defined before the next enum value. That two-phase typing seems to me to be a necessary consequence of the wording in the standard. The text of the standard could be clearer in this respect. In the following quote from the standard, I have added an editorial correction that may clarify. Note that this two-phase typing will disappear by the end of the enumeration definition. 7.2/5 ... Following the closing brace of an enum-specifier, each enumerator has the type of its enumeration. ... If the underlying type is not fixed, the [underlying] type of each enumerator [before the closing brace] is the type of its initializing value: -- If an initializer is specified for an enumerator, the initializing value has the same type as the expression and the constant-expression shall be an integral constant expression (5.19). -- If no initializer is specified for the first enumerator, the initializing value has an unspecified integral type. -- Otherwise the type of the initializing value is the same as the type of the initializing value of the preceding enumerator unless the incremented value is not representable in that type, in which case the type is an unspecified integral type sufficient to contain the incremented value. If no such type exists, the program is ill-formed. 7.2/6 For an enumeration whose underlying type is not fixed, the underlying type is an integral type that can represent all the enumerator values defined in the enumeration. If no integral type can represent all the enumerator values, the enumeration is ill-formed. It is implementation-defined which integral type is used as the underlying type except that the underlying type shall not be larger than int unless the value of an enumerator cannot fit in an int or unsigned int. If the enumerator-list is empty, the underlying type is as if the enumeration had a single enumerator with value 0.