Don't emit a warning if the `continue` appears in a switch context as changing it to `break` will break out of the switch rather than a do loop containing the switch.
Fixes https://llvm.org/PR49492.
Reviewed By: aaron.ballman
Differential Revision: https://reviews.llvm.org/D98338
equalsBoundNode("closestLoop"));
Finder->addMatcher(
- continueStmt(hasAncestor(stmt(anyOf(forStmt(), whileStmt(),
- cxxForRangeStmt(), doStmt()))
- .bind("closestLoop")),
- hasAncestor(DoWithFalse))
+ continueStmt(
+ hasAncestor(stmt(anyOf(forStmt(), whileStmt(), cxxForRangeStmt(),
+ doStmt(), switchStmt()))
+ .bind("closestLoop")),
+ hasAncestor(DoWithFalse))
.bind("continue"),
this);
}
// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: 'continue' in loop with false condition is equivalent to 'break' [bugprone-terminating-continue]
// CHECK-FIXES: if (x > 0) break;
} while (false);
+
+ switch (2) {
+ case 2:
+ do {
+ continue; // LoopInSwitch
+ // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: 'continue' in loop with false condition is equivalent to 'break' [bugprone-terminating-continue]
+ // CHECK-FIXES: break; // LoopInSwitch
+ } while (0);
+ }
}
void g() {
if (n>2) continue;
}
} while (false);
+
+ do {
+ switch (2) {
+ case 1:
+ case 2:
+ continue;
+ }
+ } while (false);
}