Issue 1018: Issue with enum compatibility

Authors: Martin Uecker
Date: 2025-07-24
Submitted against: C23
Status: Open

As reported in the GCC bug

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=121212

the standard is not clear about whether two different enums (i.e. declared with different scope) with fixed underlying type are complete or not.

Example:

enum E : int;
{
  enum E : int;
}

Previously, forward declared enums did not exist, but C23 enums with fixed underlying type are complete types - even when declared without enumerator list. This introduced a new situation where a type can be complete but the members are not known.

The standard assumes that we can determine type compatibility for two complete tagged types, i.e. we have

Moreover, two complete structure, union, or enumerated types declared with the same tag are compatible if members satisfy the following requirements:

and

For two enumerations, corresponding members shall have the same values; if one has a fixed underlying type, then the other shall have a compatible fixed underlying type.

Possible solution

The first sentence could be changed to:

Moreover, two complete structure, union, or enumerated types declared with the same tag are compatible if both declare their content and the members satisfy the following requirements:

Alternatively, one could declare those type to be compatible but then they could be redeclared inconsistently later (and then not be compatible anymore).

Finally, we could just ignore enumeration constants for type compatibility for enums with fixed underlying type (which might allow adding them incrementally, which may even be useful).