10#include "clang/AST/ASTContext.h"
11#include "clang/ASTMatchers/ASTMatchFinder.h"
12#include "clang/ASTMatchers/ASTMatchers.h"
20 forStmt(hasIncrement(forEachDescendant(
21 declRefExpr(hasType(realFloatingPointType()),
22 to(varDecl().bind(
"var")))
24 hasCondition(forEachDescendant(
25 declRefExpr(hasType(realFloatingPointType()),
26 to(varDecl(equalsBoundNode(
"var"))))
33 const auto *FS = Result.Nodes.getNodeAs<ForStmt>(
"for");
35 diag(FS->getInc()->getBeginLoc(),
"loop induction expression should not have "
36 "floating-point type")
37 << Result.Nodes.getNodeAs<DeclRefExpr>(
"inc")->getSourceRange()
38 << Result.Nodes.getNodeAs<DeclRefExpr>(
"cond")->getSourceRange();
40 if (!FS->getInc()->getType()->isRealFloatingType())
41 if (
const auto *V = Result.Nodes.getNodeAs<VarDecl>(
"var"))
42 diag(V->getBeginLoc(),
"floating-point type loop induction variable",
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.