Issue 150594
Summary [clang] Enums differing in underlying type are compatible
Labels clang
Assignees
Reporter bolshakov-a
    The following code is accepted by clang but rejected by GCC (C23 mode):
```cpp
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.

_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to