diff options
author | David Blaikie <dblaikie@gmail.com> | 2012-01-23 04:46:12 +0000 |
---|---|---|
committer | David Blaikie <dblaikie@gmail.com> | 2012-01-23 04:46:12 +0000 |
commit | 585d7795c2dddaa510b3bb1b3b18633bfcfdf643 (patch) | |
tree | be446f95e0162eff5681a650b1ad437d898d7c7a /lib/Sema/SemaStmt.cpp | |
parent | c14ec5a013883b891a71b0a112791693e9d1d1a8 (diff) |
Implement -Wswitch-enum correctly.
Clang previously implemented -Wswitch-enum the same as -Wswitch. This patch
corrects the behavior to match GCC's. The critical/only difference being that
-Wswitch-enum is not silenced by the presence of a default case in the switch.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@148679 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaStmt.cpp')
-rw-r--r-- | lib/Sema/SemaStmt.cpp | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/lib/Sema/SemaStmt.cpp b/lib/Sema/SemaStmt.cpp index f741593736..2d843393a2 100644 --- a/lib/Sema/SemaStmt.cpp +++ b/lib/Sema/SemaStmt.cpp @@ -924,30 +924,30 @@ Sema::ActOnFinishSwitchStmt(SourceLocation SwitchLoc, Stmt *Switch, } } - if (TheDefaultStmt) { - if (UnhandledNames.size() == 0) - Diag(TheDefaultStmt->getDefaultLoc(), diag::warn_unreachable_default); - else - UnhandledNames.clear(); - } + if (TheDefaultStmt && UnhandledNames.empty()) + Diag(TheDefaultStmt->getDefaultLoc(), diag::warn_unreachable_default); // Produce a nice diagnostic if multiple values aren't handled. switch (UnhandledNames.size()) { case 0: break; case 1: - Diag(CondExpr->getExprLoc(), diag::warn_missing_case1) + Diag(CondExpr->getExprLoc(), TheDefaultStmt + ? diag::warn_def_missing_case1 : diag::warn_missing_case1) << UnhandledNames[0]; break; case 2: - Diag(CondExpr->getExprLoc(), diag::warn_missing_case2) + Diag(CondExpr->getExprLoc(), TheDefaultStmt + ? diag::warn_def_missing_case2 : diag::warn_missing_case2) << UnhandledNames[0] << UnhandledNames[1]; break; case 3: - Diag(CondExpr->getExprLoc(), diag::warn_missing_case3) + Diag(CondExpr->getExprLoc(), TheDefaultStmt + ? diag::warn_def_missing_case3 : diag::warn_missing_case3) << UnhandledNames[0] << UnhandledNames[1] << UnhandledNames[2]; break; default: - Diag(CondExpr->getExprLoc(), diag::warn_missing_cases) + Diag(CondExpr->getExprLoc(), TheDefaultStmt + ? diag::warn_def_missing_cases : diag::warn_missing_cases) << (unsigned)UnhandledNames.size() << UnhandledNames[0] << UnhandledNames[1] << UnhandledNames[2]; break; |