On Sun, 19 May 2024, Martin Uecker wrote: > c23 specifies that the type of a redeclared enumerator is the one of the > previous declaration. Convert initializers with different type > accordingly > and add -Woverflow warning.
It doesn't make sense to use -Woverflow. Either the value is the same (in which case it fits in the desired type), or it's different (and you should get the "conflicting redeclaration of enumerator" error or some equivalent error, whether or not the value in the redeclaration fits in the previous type). Note that this includes both explicit values and values determined by adding 1 implicitly. E.g. enum e { A = 0, B = UINT_MAX }; enum e { B = UINT_MAX, A }; is not valid, because in the redefinition, A gets the value 1 greater than UINT_MAX (which is not representable in unsigned int) - there is *not* an addition in type unsigned int, or in type enum e. The constraint violated is the general one "If an identifier has no linkage, there shall be no more than one declaration of the identifier (in a declarator or type specifier) with the same scope and in the same name space, except that: ... enumeration constants and tags may be redeclared as specified in 6.7.3.3 and 6.7.3.4, respectively." (where 6.7.3.3 says "Enumeration constants can be redefined in the same scope with the same value as part of a redeclaration of the same enumerated type." - as the redefinition is not with the same value, the "as specified in 6.7.3.3" is not satisfied and so the general constraint against redeclarations with no linkage applies). -- Joseph S. Myers josmy...@redhat.com