https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115109
Bug ID: 115109 Summary: Incorrect type of enumeration constant in redeclaration of enumeration constant (C23) Product: gcc Version: 14.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: luigighiron at gmail dot com Target Milestone: --- GCC does not accept the following code: static_assert(INT_WIDTH<42&&LONG_WIDTH>=42); enum E{a=1UL<<40,b=1}; enum E{a=1ULL<<40,b=_Generic(a,unsigned long:1,default:2)}; The static_assert is there to document the assumptions that should make this code valid. Here is the relevant part of the standard: > During the processing of each enumeration constant in the enumerator list, > the type of the enumeration constant shall be: > > - the previously declared type, if it is a redeclaration of the same > enumeration constant; or, > > - the enumerated type, for an enumeration with fixed underlying type; or, > > - int, if there are no previous enumeration constants in the enumerator list > and no explicit = with a defining integer constant expression; or, > > - int, if given explicitly with = and the value of the integer constant > expression is representable by an int; or, > > - the type of the integer constant expression, if given explicitly with = and > if the value of the integer constant expression is not representable by int; > or, > > ... Section 6.7.3.3 "Enumeration specifiers" Paragraph 12 N3220 The types of the enumeration constants 'a' and 'b' in the first enumeration specifier should be unsigned long and int, respectively. Then in the second enumeration declaration, they should have the same types as the first enumeration declaration because of the first item in the list in the above quote. GCC does not seem to follow this and makes the type of the enumeration constant 'a' unsigned long long because the type of the expression is unsigned long long.