aboutsummaryrefslogtreecommitdiff
path: root/lib/Sema/SemaStmt.cpp
diff options
context:
space:
mode:
authorDavid Blaikie <dblaikie@gmail.com>2012-01-21 18:12:07 +0000
committerDavid Blaikie <dblaikie@gmail.com>2012-01-21 18:12:07 +0000
commit31ceb61172bca7ebc3fb90e9125864c7a29c55c0 (patch)
treed605bb1e6086fadf6341cc1b65bdf886a5698bdd /lib/Sema/SemaStmt.cpp
parentf3c1ca6bced3f79ec6d76f1bcb05c5ae6944ce0b (diff)
Add -Wswitch-enum-redundant-default.
This warning acts as the complement to the main -Wswitch-enum warning (which warns whenever a switch over enum without a default doesn't cover all values of the enum) & has been an an-doc coding convention in LLVM and Clang in my experience. The purpose is to ensure there's never a "dead" default in a switch-over-enum because this would hide future -Wswitch-enum errors. The name warning has a separate flag name so it can be disabled but it's grouped under -Wswitch-enum & is on-by-default because of this. The existing violations of this rule in test cases have had the warning disabled & I've added a specific test for the new behavior (many negative cases already exist in the same test file - and none regressed - so I didn't add more). Reviewed by Ted Kremenek ( http://lists.cs.uiuc.edu/pipermail/cfe-commits/Week-of-Mon-20120116/051690.html ) git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@148640 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaStmt.cpp')
-rw-r--r--lib/Sema/SemaStmt.cpp10
1 files changed, 8 insertions, 2 deletions
diff --git a/lib/Sema/SemaStmt.cpp b/lib/Sema/SemaStmt.cpp
index a53e397243..0be3e43b5a 100644
--- a/lib/Sema/SemaStmt.cpp
+++ b/lib/Sema/SemaStmt.cpp
@@ -924,11 +924,17 @@ Sema::ActOnFinishSwitchStmt(SourceLocation SwitchLoc, Stmt *Switch,
if (RI == CaseRanges.end() || EI->first < RI->first) {
hasCasesNotInSwitch = true;
- if (!TheDefaultStmt)
- UnhandledNames.push_back(EI->second->getDeclName());
+ UnhandledNames.push_back(EI->second->getDeclName());
}
}
+ if (TheDefaultStmt) {
+ if (UnhandledNames.size() == 0)
+ Diag(TheDefaultStmt->getDefaultLoc(), diag::warn_unreachable_default);
+ else
+ UnhandledNames.clear();
+ }
+
// Produce a nice diagnostic if multiple values aren't handled.
switch (UnhandledNames.size()) {
case 0: break;