forked from OSchip/llvm-project
For -Wswitch-enum warnings, be sure to look through typedefs of enum
types. Fixes <rdar://problem/7643909>. llvm-svn: 96531
This commit is contained in:
parent
81001ab490
commit
12ea0f4ef9
|
@ -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();
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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'}}
|
||||
|
|
Loading…
Reference in New Issue