Fix temporary enumerator type in C redefinitions
Corrects type handling for enumerators during C redefinitions, resolving a bug in type visibility.
This commit fixes a bug in GCC’s C front-end where the visible type for an enumerator was incorrectly handled during the redefinition of an enumerated type. Previously, the underlying type was used internally, leading to visibility issues. The fix ensures that the visible type remains the enumerated type itself, aligning with the language standard and resolving PR128335. A new test case is added to verify the correction.
In Details
The c-decl.cc file's build_enumerator function in GCC's C front-end is modified to correct the type associated with enumerators when an enum type is redefined. Previously, the internal computation used the underlying type, but the externally visible type should have been the enum type itself (or int if applicable). This commit ensures the correct type is maintained, preventing issues in scenarios like PR128335 where redeclarations might expose incorrect types.
- enumerator
- A named constant value within an enumerated type. For example, in
enum Color { RED, GREEN, BLUE };, RED, GREEN, and BLUE are enumerators. - underlying type
- The fundamental data type (e.g.,
int,long) that an enumerated type is based on. The C standard specifies rules for determining this type.