[PATCH] D98338: [clang-tidy] Fix bugprone-terminating-continue when continue appears inside a switch
Nathan James via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sat Mar 20 03:59:55 PDT 2021
This revision was automatically updated to reflect the committed changes.
Closed by commit rG4dd92d61dbc4: [clang-tidy] Fix bugprone-terminating-continue when continue appears inside a… (authored by njames93).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D98338/new/
https://reviews.llvm.org/D98338
Files:
clang-tools-extra/clang-tidy/bugprone/TerminatingContinueCheck.cpp
clang-tools-extra/test/clang-tidy/checkers/bugprone-terminating-continue.cpp
Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-terminating-continue.cpp
===================================================================
--- clang-tools-extra/test/clang-tidy/checkers/bugprone-terminating-continue.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-terminating-continue.cpp
@@ -32,6 +32,15 @@
// 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() {
@@ -62,4 +71,12 @@
if (n>2) continue;
}
} while (false);
+
+ do {
+ switch (2) {
+ case 1:
+ case 2:
+ continue;
+ }
+ } while (false);
}
Index: clang-tools-extra/clang-tidy/bugprone/TerminatingContinueCheck.cpp
===================================================================
--- clang-tools-extra/clang-tidy/bugprone/TerminatingContinueCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/TerminatingContinueCheck.cpp
@@ -26,10 +26,11 @@
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);
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D98338.332096.patch
Type: text/x-patch
Size: 1930 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210320/c1dddd92/attachment-0001.bin>
More information about the cfe-commits
mailing list