diff options
author | Fariborz Jahanian <fjahanian@apple.com> | 2012-03-21 20:56:29 +0000 |
---|---|---|
committer | Fariborz Jahanian <fjahanian@apple.com> | 2012-03-21 20:56:29 +0000 |
commit | 54faba4f7f3f0e8f1376da1c459312596ad5486d (patch) | |
tree | 174069c0ad28cf09478b3868bd8b4a0721973590 | |
parent | 9354f6aaa70e1543d122644fee0c3f834324d2fc (diff) |
For enums with no tag name, display its location in
the diagnostic instead of displaying ''.
// rdar://11082110
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@153219 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Sema/SemaStmt.cpp | 6 | ||||
-rw-r--r-- | test/Sema/switch.c | 49 |
2 files changed, 36 insertions, 19 deletions
diff --git a/lib/Sema/SemaStmt.cpp b/lib/Sema/SemaStmt.cpp index 1ddedcfe68..6db66a5eff 100644 --- a/lib/Sema/SemaStmt.cpp +++ b/lib/Sema/SemaStmt.cpp @@ -881,7 +881,7 @@ Sema::ActOnFinishSwitchStmt(SourceLocation SwitchLoc, Stmt *Switch, EI++; if (EI == EIend || EI->first > CI->first) Diag(CI->second->getLHS()->getExprLoc(), diag::warn_not_in_enum) - << ED->getDeclName(); + << CondTypeBeforePromotion; } // See which of case ranges aren't in enum EI = EnumVals.begin(); @@ -892,7 +892,7 @@ Sema::ActOnFinishSwitchStmt(SourceLocation SwitchLoc, Stmt *Switch, if (EI == EIend || EI->first != RI->first) { Diag(RI->second->getLHS()->getExprLoc(), diag::warn_not_in_enum) - << ED->getDeclName(); + << CondTypeBeforePromotion; } llvm::APSInt Hi = @@ -902,7 +902,7 @@ Sema::ActOnFinishSwitchStmt(SourceLocation SwitchLoc, Stmt *Switch, EI++; if (EI == EIend || EI->first != Hi) Diag(RI->second->getRHS()->getExprLoc(), diag::warn_not_in_enum) - << ED->getDeclName(); + << CondTypeBeforePromotion; } // Check which enum vals aren't in switch diff --git a/test/Sema/switch.c b/test/Sema/switch.c index 5c8ebf516c..a7a7f60492 100644 --- a/test/Sema/switch.c +++ b/test/Sema/switch.c @@ -109,14 +109,14 @@ void test7() { switch(a) { case A: case B: - case 3: // expected-warning{{case value not in enumerated type ''}} + case 3: // expected-warning{{case value not in enumerated type 'enum <anonymous enum}} break; } switch(a) { case A: case B: - case 3 ... //expected-warning{{case value not in enumerated type ''}} - 4: //expected-warning{{case value not in enumerated type ''}} + case 3 ... //expected-warning{{case value not in enumerated type 'enum <anonymous enum}} + 4: //expected-warning{{case value not in enumerated type 'enum <anonymous enum}} break; } switch(a) { @@ -124,16 +124,16 @@ void test7() { break; } switch(a) { - case 0 ... 2: //expected-warning{{case value not in enumerated type ''}} + case 0 ... 2: //expected-warning{{case value not in enumerated type 'enum <anonymous enum}} break; } switch(a) { - case 1 ... 3: //expected-warning{{case value not in enumerated type ''}} + case 1 ... 3: //expected-warning{{case value not in enumerated type 'enum <anonymous enum}} break; } switch(a) { - case 0 ... //expected-warning{{case value not in enumerated type ''}} - 3: //expected-warning{{case value not in enumerated type ''}} + case 0 ... //expected-warning{{case value not in enumerated type 'enum <anonymous enum}} + 3: //expected-warning{{case value not in enumerated type 'enum <anonymous enum}} break; } @@ -167,11 +167,11 @@ void test9() { C = 1 } a; switch(a) { - case 0: //expected-warning{{case value not in enumerated type ''}} + case 0: //expected-warning{{case value not in enumerated type 'enum <anonymous enum}} case 1: - case 2: //expected-warning{{case value not in enumerated type ''}} + case 2: //expected-warning{{case value not in enumerated type 'enum <anonymous enum}} case 3: - case 4: //expected-warning{{case value not in enumerated type ''}} + case 4: //expected-warning{{case value not in enumerated type 'enum <anonymous enum}} break; } } @@ -184,14 +184,14 @@ void test10() { D = 12 } a; switch(a) { - case 0 ... //expected-warning{{case value not in enumerated type ''}} - 1: //expected-warning{{case value not in enumerated type ''}} + case 0 ... //expected-warning{{case value not in enumerated type 'enum <anonymous enum}} + 1: //expected-warning{{case value not in enumerated type 'enum <anonymous enum}} case 2 ... 4: - case 5 ... //expected-warning{{case value not in enumerated type ''}} - 9: //expected-warning{{case value not in enumerated type ''}} + case 5 ... //expected-warning{{case value not in enumerated type 'enum <anonymous enum}} + 9: //expected-warning{{case value not in enumerated type 'enum <anonymous enum}} case 10 ... 12: - case 13 ... //expected-warning{{case value not in enumerated type ''}} - 16: //expected-warning{{case value not in enumerated type ''}} + case 13 ... //expected-warning{{case value not in enumerated type 'enum <anonymous enum}} + 16: //expected-warning{{case value not in enumerated type 'enum <anonymous enum}} break; } } @@ -303,3 +303,20 @@ int test18() { default: return 2; // expected-warning {{default label in switch which covers all enumeration values}} } } + +// rdar://110822110 +typedef enum { + kOne = 1, +} Ints; + +void rdar110822110(Ints i) +{ + switch (i) { + case kOne: + break; + case 2: // expected-warning {{case value not in enumerated type 'Ints'}} + break; + default: // expected-warning {{default label in switch which covers all enumeration values}} + break; + } +} |