10 #include "clang/AST/ASTContext.h"
11 #include "clang/ASTMatchers/ASTMatchFinder.h"
12 #include "clang/Lex/Lexer.h"
13 #include "clang/Tooling/FixIt.h"
21 void TerminatingContinueCheck::registerMatchers(MatchFinder *Finder) {
22 const auto doWithFalse =
23 doStmt(hasCondition(ignoringImpCasts(
24 anyOf(cxxBoolLiteral(equals(
false)), integerLiteral(equals(0)),
25 cxxNullPtrLiteralExpr(), gnuNullExpr()))),
26 equalsBoundNode(
"closestLoop"));
29 continueStmt(hasAncestor(stmt(anyOf(forStmt(), whileStmt(),
30 cxxForRangeStmt(), doStmt()))
31 .bind(
"closestLoop")),
32 hasAncestor(doWithFalse))
37 void TerminatingContinueCheck::check(
const MatchFinder::MatchResult &Result) {
38 const auto *ContStmt = Result.Nodes.getNodeAs<ContinueStmt>(
"continue");
41 diag(ContStmt->getBeginLoc(),
42 "'continue' in loop with false condition is equivalent to 'break'")
43 << tooling::fixit::createReplacement(*ContStmt,
"break");