aboutsummaryrefslogtreecommitdiff
path: root/test/SemaCXX/warn-unique-enum.cpp
diff options
context:
space:
mode:
authorRichard Trieu <rtrieu@google.com>2012-05-30 01:01:11 +0000
committerRichard Trieu <rtrieu@google.com>2012-05-30 01:01:11 +0000
commit7af7de7d6b121132dfe8c3b9b5febe2b37aafd62 (patch)
treea8ff942ffd9358d802381be56682c85b218a0467 /test/SemaCXX/warn-unique-enum.cpp
parent6fcb3727e31280ba816dc86d024586b8c5933c13 (diff)
Add new -Wunique-enum which will warn on enums which all elements have the
same value and were initialized with literals. Clang will warn on code like this: enum A { FIRST = 1, SECOND = 1 }; git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@157666 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/SemaCXX/warn-unique-enum.cpp')
-rw-r--r--test/SemaCXX/warn-unique-enum.cpp16
1 files changed, 16 insertions, 0 deletions
diff --git a/test/SemaCXX/warn-unique-enum.cpp b/test/SemaCXX/warn-unique-enum.cpp
new file mode 100644
index 0000000000..ddafc16aab
--- /dev/null
+++ b/test/SemaCXX/warn-unique-enum.cpp
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 %s -fsyntax-only -verify -Wunique-enum
+enum A { A1 = 1, A2 = 1, A3 = 1 }; // expected-warning {{all elements of 'A' are initialized with literals to value 1}}
+enum { B1 = 1, B2 = 1, B3 = 1 }; // expected-warning {{all elements of anonymous enum are initialized with literals to value 1}}
+enum C { C1 = true, C2 = true}; // expected-warning {{all elements of 'C' are initialized with literals to value 1}}
+enum D { D1 = 5, D2 = 5L, D3 = 5UL, D4 = 5LL, D5 = 5ULL }; // expected-warning {{all elements of 'D' are initialized with literals to value 5}}
+
+// Don't warn on enums with less than 2 elements.
+enum E { E1 = 4 };
+enum F { F1 };
+enum G {};
+
+// Don't warn when integer literals do not initialize the elements.
+enum H { H1 = 4, H_MAX = H1, H_MIN = H1 };
+enum I { I1 = H1, I2 = 4 };
+enum J { J1 = 4, J2 = I2 };
+enum K { K1, K2, K3, K4 };