[clang] [Clang][Sema] Fix missing warning when comparing mismatched enums in … (PR #81418)
Shafik Yaghmour via cfe-commits
cfe-commits at lists.llvm.org
Thu Feb 22 11:57:23 PST 2024
================
@@ -0,0 +1,42 @@
+// RUN: %clang_cc1 -x c -fsyntax-only -verify -Wenum-compare -Wno-unused-comparison %s
+// RUN: %clang_cc1 -x c++ -fsyntax-only -verify -Wenum-compare -Wno-unused-comparison %s
+
+typedef enum EnumA {
+ A
+} EnumA;
+
+enum EnumB {
+ B
+};
+
+enum {
+ C
+};
+
+void foo(void) {
+ enum EnumA a = A;
+ enum EnumB b = B;
+ A == B;
+ // expected-warning at -1 {{comparison of different enumeration types}}
+ a == (B);
+ // expected-warning at -1 {{comparison of different enumeration types}}
+ a == b;
+ // expected-warning at -1 {{comparison of different enumeration types}}
+ A > B;
+ // expected-warning at -1 {{comparison of different enumeration types}}
+ A >= b;
+ // expected-warning at -1 {{comparison of different enumeration types}}
+ a > b;
+ // expected-warning at -1 {{comparison of different enumeration types}}
+ (A) <= ((B));
+ // expected-warning at -1 {{comparison of different enumeration types}}
+ a < B;
+ // expected-warning at -1 {{comparison of different enumeration types}}
+ a < b;
+ // expected-warning at -1 {{comparison of different enumeration types}}
+
+ // In the following cases we purposefully differ from GCC and dont warn
+ a == C;
+ A < C;
+ b >= C;
+}
----------------
shafik wrote:
Please add a newline at the end of the file
https://github.com/llvm/llvm-project/pull/81418
More information about the cfe-commits
mailing list