Issue 147370
Summary [Clang] `typeof(*fixed-type enumeration*)` resolves to the underlying type, unlike GCC
Labels clang
Assignees
Reporter fuhsnn
    https://godbolt.org/z/zce5YzqjY

```C
#include <stdio.h>
int main(void) {
    {
        enum { A };
        enum { B };
        printf("%d\n", _Generic(       A , typeof(B):1, default:0)); // Both 1
        printf("%d\n", _Generic(typeof(A), typeof(B):1, default:0)); // Both 1
    }
    {
        printf("%d\n", _Generic(typeof(enum { A }), typeof(enum { B }):1, default:0)); // Both 0
 }
    {
        enum : int { A };
        enum : int { B };
 printf("%d\n", _Generic(       A , typeof(B):1, default:0)); // Clang: 1, GCC: 0
        printf("%d\n", _Generic(typeof(A), typeof(B):1, default:0)); // Clang: 1, GCC: 0
    }
    {
        printf("%d\n", _Generic(typeof(enum : int { A }), typeof(enum : int { B }):1, default:0)); // Both 0
    }
}
```

It seems that GCC treats `typeof` of fixed-type enumerations as `enum : int` and concludes they are not compatible. Clang, on the contrary, sees them as `int` and thus compatible.

I didn't find in n3550 pdf when should fixed-type enumerations drop their "is enum" property, so can't say which is more conformant, though I prefer the Clang behavior as more intuitive.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to