52 lines · c
1// RUN: %clang_cc1 -x c -fsyntax-only -verify -Wenum-compare -Wno-unused-comparison %s2// RUN: %clang_cc1 -x c++ -fsyntax-only -verify -Wenum-compare -Wno-unused-comparison %s3 4// In C enumerators (i.e enumeration constants) have type int (until C23). In5// order to support diagnostics such as -Wenum-compare we pretend they have the6// type of their enumeration.7 8typedef enum EnumA {9 A10} EnumA;11 12enum EnumB {13 B,14 B1 = 1,15 // In C++ this comparison doesnt warn as enumerators dont have the type of16 // their enumeration before the closing brace. We mantain the same behavior17 // in C.18 B2 = A == B119};20 21enum {22 C23};24 25void foo(void) {26 enum EnumA a = A;27 enum EnumB b = B;28 A == B;29 // expected-warning@-1 {{comparison of different enumeration types}}30 a == (B);31 // expected-warning@-1 {{comparison of different enumeration types}}32 a == b;33 // expected-warning@-1 {{comparison of different enumeration types}}34 A > B;35 // expected-warning@-1 {{comparison of different enumeration types}}36 A >= b;37 // expected-warning@-1 {{comparison of different enumeration types}}38 a > b;39 // expected-warning@-1 {{comparison of different enumeration types}}40 (A) <= ((B));41 // expected-warning@-1 {{comparison of different enumeration types}}42 a < B;43 // expected-warning@-1 {{comparison of different enumeration types}}44 a < b;45 // expected-warning@-1 {{comparison of different enumeration types}}46 47 // In the following cases we purposefully differ from GCC and dont warn 48 a == C; 49 A < C;50 b >= C; 51}52