]> granicus.if.org Git - clang/commitdiff
Don't offer '[[clang::fallthrough]];' fix-it when a fall-through occurs to a
authorAlexander Kornienko <alexfh@gmail.com>
Sat, 26 May 2012 00:49:15 +0000 (00:49 +0000)
committerAlexander Kornienko <alexfh@gmail.com>
Sat, 26 May 2012 00:49:15 +0000 (00:49 +0000)
switch label immediately followed by a 'break;'.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@157508 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/AnalysisBasedWarnings.cpp
test/SemaCXX/switch-implicit-fallthrough.cpp

index bbcd6a8e14c4faa97335458784074fca4f29f093..562fe68292ddecf54112c56d50e8c16bb3ece3e2 100644 (file)
@@ -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; ");
index db5508a125717488dfe281cfd51af98767e56a87..02532e801ac003b5ee1b6df13233db4e3882a222 100644 (file)
@@ -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: