[cfe-commits] r96531 - in /cfe/trunk: lib/Sema/SemaStmt.cpp test/Sema/switch.c test/SemaCXX/condition.cpp

Douglas Gregor dgregor at apple.com
Wed Feb 17 15:29:11 PST 2010


Author: dgregor
Date: Wed Feb 17 17:29:11 2010
New Revision: 96531

URL: http://llvm.org/viewvc/llvm-project?rev=96531&view=rev
Log:
For -Wswitch-enum warnings, be sure to look through typedefs of enum
types. Fixes <rdar://problem/7643909>.

Modified:
    cfe/trunk/lib/Sema/SemaStmt.cpp
    cfe/trunk/test/Sema/switch.c
    cfe/trunk/test/SemaCXX/condition.cpp

Modified: cfe/trunk/lib/Sema/SemaStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaStmt.cpp?rev=96531&r1=96530&r2=96531&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaStmt.cpp (original)
+++ cfe/trunk/lib/Sema/SemaStmt.cpp Wed Feb 17 17:29:11 2010
@@ -752,7 +752,7 @@
 
     // 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();

Modified: cfe/trunk/test/Sema/switch.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/switch.c?rev=96531&r1=96530&r2=96531&view=diff

==============================================================================
--- cfe/trunk/test/Sema/switch.c (original)
+++ cfe/trunk/test/Sema/switch.c Wed Feb 17 17:29:11 2010
@@ -223,3 +223,20 @@
       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;
+}

Modified: cfe/trunk/test/SemaCXX/condition.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/condition.cpp?rev=96531&r1=96530&r2=96531&view=diff

==============================================================================
--- cfe/trunk/test/SemaCXX/condition.cpp (original)
+++ cfe/trunk/test/SemaCXX/condition.cpp Wed Feb 17 17:29:11 2010
@@ -18,7 +18,8 @@
 
   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'}}





More information about the cfe-commits mailing list