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