10#include "clang/AST/ASTContext.h"
11#include "clang/ASTMatchers/ASTMatchFinder.h"
18 const auto IntType = hasType(isInteger());
20 const auto BinaryOperators = binaryOperator(
21 hasAnyOperatorName(
"%",
"<<",
">>",
"<<",
"^",
"|",
"&",
"||",
"&&",
"<",
22 ">",
"<=",
">=",
"==",
"!="));
24 const auto UnaryOperators = unaryOperator(hasAnyOperatorName(
"~",
"!"));
26 const auto Exceptions =
27 anyOf(BinaryOperators, conditionalOperator(), binaryConditionalOperator(),
28 callExpr(IntType), explicitCastExpr(IntType), UnaryOperators);
33 hasOperatorName(
"/"), hasLHS(expr(IntType)),
34 hasRHS(expr(IntType)),
35 hasAncestor(castExpr(hasCastKind(CK_IntegralToFloating))
37 unless(hasAncestor(expr(
39 hasAncestor(castExpr(equalsBoundNode(
"FloatCast")))))))
45 const auto *IntDiv = Result.Nodes.getNodeAs<BinaryOperator>(
"IntDiv");
46 diag(IntDiv->getBeginLoc(),
"result of integer division used in a floating "
47 "point context; possible loss of precision");
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.