aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2010-02-17 23:29:11 +0000
committerDouglas Gregor <dgregor@apple.com>2010-02-17 23:29:11 +0000
commit30ab37122300a5f6664b8ae2d0b43b4396eb6bcb (patch)
treedc1624fec18cd12c6e991b6e679264354da13e06
parent0b3b4363df8d24905cef8254b0841ef1c9a8bfac (diff)
For -Wswitch-enum warnings, be sure to look through typedefs of enum
types. Fixes <rdar://problem/7643909>. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@96531 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Sema/SemaStmt.cpp2
-rw-r--r--test/Sema/switch.c17
-rw-r--r--test/SemaCXX/condition.cpp3
3 files changed, 20 insertions, 2 deletions
diff --git a/lib/Sema/SemaStmt.cpp b/lib/Sema/SemaStmt.cpp
index fa42634a34..d9f5b38eb9 100644
--- a/lib/Sema/SemaStmt.cpp
+++ b/lib/Sema/SemaStmt.cpp
@@ -752,7 +752,7 @@ Sema::ActOnFinishSwitchStmt(SourceLocation SwitchLoc, StmtArg Switch,
// Check to see if switch is over an Enum and handles all of its
// values
- const EnumType* ET = dyn_cast<EnumType>(CondTypeBeforePromotion);
+ const EnumType* ET = CondTypeBeforePromotion->getAs<EnumType>();
// If switch has default case, then ignore it.
if (!CaseListIsErroneous && !TheDefaultStmt && ET) {
const EnumDecl *ED = ET->getDecl();
diff --git a/test/Sema/switch.c b/test/Sema/switch.c
index 2690ad28e9..9905c4b025 100644
--- a/test/Sema/switch.c
+++ b/test/Sema/switch.c
@@ -223,3 +223,20 @@ void test12() {
break;
}
}
+
+// <rdar://problem/7643909>
+typedef enum {
+ val1,
+ val2,
+ val3
+} my_type_t;
+
+int test13(my_type_t t) {
+ switch(t) { // expected-warning{{enumeration value 'val3' not handled in switch}}
+ case val1:
+ return 1;
+ case val2:
+ return 2;
+ }
+ return -1;
+}
diff --git a/test/SemaCXX/condition.cpp b/test/SemaCXX/condition.cpp
index fe802d0555..b3e862dc1b 100644
--- a/test/SemaCXX/condition.cpp
+++ b/test/SemaCXX/condition.cpp
@@ -18,7 +18,8 @@ void test() {
while (struct S {} x=0) ; // expected-error {{types may not be defined in conditions}} expected-error {{no viable conversion}} expected-error {{value of type 'struct S' is not contextually convertible to 'bool'}} expected-note{{candidate constructor (the implicit copy constructor)}}
while (struct {} x=0) ; // expected-error {{types may not be defined in conditions}} expected-error {{no viable conversion}} expected-error {{value of type 'struct <anonymous>' is not contextually convertible to 'bool'}} expected-note{{candidate constructor (the implicit copy constructor)}}
- switch (enum {E} x=0) ; // expected-error {{types may not be defined in conditions}} expected-error {{cannot initialize}}
+ switch (enum {E} x=0) ; // expected-error {{types may not be defined in conditions}} expected-error {{cannot initialize}} \
+ // expected-warning{{enumeration value 'E' not handled in switch}}
if (int x=0) { // expected-note 2 {{previous definition is here}}
int x; // expected-error {{redefinition of 'x'}}