10#include "clang/AST/ASTContext.h"
11#include "clang/ASTMatchers/ASTMatchFinder.h"
12#include "clang/Lex/Lexer.h"
13#include "clang/Tooling/FixIt.h"
20 const auto DoWithFalse =
21 doStmt(hasCondition(ignoringImpCasts(
22 anyOf(cxxBoolLiteral(equals(
false)), integerLiteral(equals(0)),
23 cxxNullPtrLiteralExpr(), gnuNullExpr()))),
24 equalsBoundNode(
"closestLoop"));
28 hasAncestor(stmt(anyOf(forStmt(), whileStmt(), cxxForRangeStmt(),
29 doStmt(), switchStmt()))
30 .bind(
"closestLoop")),
31 hasAncestor(DoWithFalse))
37 const auto *ContStmt = Result.Nodes.getNodeAs<ContinueStmt>(
"continue");
40 diag(ContStmt->getBeginLoc(),
41 "'continue' in loop with false condition is equivalent to 'break'")
42 << tooling::fixit::createReplacement(*ContStmt,
"break");
DiagnosticBuilder diag(SourceLocation Loc, StringRef Description, DiagnosticIDs::Level Level=DiagnosticIDs::Warning)
Add a diagnostic with the check's name.
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Override this to register AST matchers with Finder.
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
ClangTidyChecks that register ASTMatchers should do the actual work in here.