Skip to content

[clang] Enums differing in underlying type are compatible #150594

@bolshakov-a

Description

@bolshakov-a

The following code is accepted by clang but rejected by GCC (C23 mode):

enum E : int {A, B, C};

enum E e;

int main() {
  extern enum E Fn();
  enum E {A, B, C};
  extern enum E Fn();
  return __builtin_types_compatible_p(enum E, typeof(e));
}

https://godbolt.org/z/Eab5nz3q9
Compiled by clang, it returns 1, whereas if compiled by GCC (provided that the second Fn() declaration is removed) it returns 0.

I think GCC behavior is correct because 6.2.7 "Compatible type and composite type" states:

For two enumerations, ... if one has a fixed underlying type, then the other shall have a compatible fixed underlying type.

Metadata

Metadata

Assignees

No one assigned

    Labels

    c23clang:frontendLanguage frontend issues, e.g. anything involving "Sema"confirmedVerified by a second party

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions