checks if a 'continue' statement terminates the loop
Details
Diff Detail
Event Timeline
Please don't forget to add cfe-commits to Subscribers: when initially sending the patch for review. Otherwise nobody on the list will see it.
Could you run the check on LLVM+Clang and post a summary of your findings here?
Hi,
Result of a clang-tidy run on LLVM+Clang with only misc-terminating-continue turned on:
1 Warning:
llvm/tools/clang/lib/Parse/ParseTentative.cpp:1678:7: warning: terminating 'continue' [misc-terminating-continue]
continue; ^~~~~~~~~ break
I think this check could land in the bugprone module.
Given this situation won't appear a lot in codebases, did you check other codebases than LLVM?
clang-tidy/misc/TerminatingContinueCheck.h | ||
---|---|---|
20 | I think you can make one sentence out of both. | |
docs/clang-tidy/checks/misc-terminating-continue.rst | ||
7 | Maybe rephrase a little: loops with a condition always evaluating to false or something like it. | |
22 | Please emphasize this location, so that it is absolutly clear what you mean. |
clang-tidy/misc/TerminatingContinueCheck.cpp | ||
---|---|---|
43 | It was not clear to me what a "terminating 'continue'" was, just from seeing this error message. Wouldn't it make more sense to emit a self-explanatory diagnostic, such as 'continue', in loop with false condition, is equivalent to 'break' ? And then you could even suggest a fixit of replacing 'continue' with 'break'... oh, which you already do. :) | |
test/clang-tidy/misc-terminating-continue.cpp | ||
8 | I initially expected to see tests also for goto L1; while (false) { L1: continue; // 'continue' is equivalent to 'break' } int v = 0; goto L1; for (; false; ++v) { L1: continue; // 'continue' is NOT equivalent to 'break' } although I assume your current patch doesn't actually diagnose the former, and that's probably fine. |
test/clang-tidy/misc-terminating-continue.cpp | ||
---|---|---|
8 | I think both of your examples are out of scope for this check and are they realistic? The usage of goto is addressed in cppcoreguidelines-avoid-goto |
Please move the check to bugprone- module. clang-tidy/rename_check.py script should do most of the job (you'll have to remove the unnecessary "renamed check ..." entry in the release notes).
clang-tidy/misc/TerminatingContinueCheck.cpp | ||
---|---|---|
27 | The "doWithFalseCond" binding isn't used and can be removed. | |
30–33 | Can we avoid repeated traversal of ancestors by inverting the order of matchers here? E.g. continueStmt(hasAncestor(stmt(anyOf(forStmt(), whileStmt(), ...)).bind("closestLoop")), hasAncestor(doWithFalse)) | |
45 | The variable doesn't make the code any better, please remove it. The creation of the replacement could be formulated a bit more succint: tooling::fixit::createReplacement(ContStmt, "break"); | |
docs/clang-tidy/checks/misc-terminating-continue.rst | ||
12–21 | Quoting a whole method from Clang isn't necessary for the purpose of this documentation. I'd go with a simpler example. |
Weird. When I was writing the comment, the code looked identical to the version from Mar 27. It may have been something wrong with my browser, with the Phabricator, or with the way I used it. Anyway, looks good now. Sorry for the confusion.
Do you need someone to commit the patch for you?
I think you can make one sentence out of both.