diff options
author | Alexander Kornienko <alexfh@gmail.com> | 2012-05-26 00:49:15 +0000 |
---|---|---|
committer | Alexander Kornienko <alexfh@gmail.com> | 2012-05-26 00:49:15 +0000 |
commit | a189d8976f1193b788508a1a29b2e9d0aca06aca (patch) | |
tree | dfe54218ff624ad0e89268fa479e4c4a9037889b | |
parent | 976f266b969e03ef08b37b5f4aaf013f48f1ba6e (diff) |
Don't offer '[[clang::fallthrough]];' fix-it when a fall-through occurs to a
switch label immediately followed by a 'break;'.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@157508 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Sema/AnalysisBasedWarnings.cpp | 7 | ||||
-rw-r--r-- | test/SemaCXX/switch-implicit-fallthrough.cpp | 2 |
2 files changed, 7 insertions, 2 deletions
diff --git a/lib/Sema/AnalysisBasedWarnings.cpp b/lib/Sema/AnalysisBasedWarnings.cpp index bbcd6a8e14..562fe68292 100644 --- a/lib/Sema/AnalysisBasedWarnings.cpp +++ b/lib/Sema/AnalysisBasedWarnings.cpp @@ -777,8 +777,11 @@ static void DiagnoseSwitchLabelsFallthrough(Sema &S, AnalysisDeclContext &AC) { if (L.isMacroID()) continue; if (S.getLangOpts().CPlusPlus0x) { - S.Diag(L, diag::note_insert_fallthrough_fixit) << - FixItHint::CreateInsertion(L, "[[clang::fallthrough]]; "); + const Stmt *Term = B.getTerminator(); + if (!(B.empty() && Term && isa<BreakStmt>(Term))) { + S.Diag(L, diag::note_insert_fallthrough_fixit) << + FixItHint::CreateInsertion(L, "[[clang::fallthrough]]; "); + } } S.Diag(L, diag::note_insert_break_fixit) << FixItHint::CreateInsertion(L, "break; "); diff --git a/test/SemaCXX/switch-implicit-fallthrough.cpp b/test/SemaCXX/switch-implicit-fallthrough.cpp index db5508a125..02532e801a 100644 --- a/test/SemaCXX/switch-implicit-fallthrough.cpp +++ b/test/SemaCXX/switch-implicit-fallthrough.cpp @@ -33,6 +33,8 @@ int fallthrough(int n) { } case 6: // expected-warning{{unannotated fall-through between switch labels}} expected-note{{insert '[[clang::fallthrough]];' to silence this warning}} expected-note{{insert 'break;' to avoid fall-through}} n += 300; + case 66: // expected-warning{{unannotated fall-through between switch labels}} expected-note{{insert 'break;' to avoid fall-through}} + break; } switch (n / 20) { case 7: |