11 #include "clang/AST/ASTContext.h"
12 #include "clang/ASTMatchers/ASTMatchFinder.h"
14 using namespace clang::ast_matchers;
18 namespace cppcoreguidelines {
20 void ProBoundsPointerArithmeticCheck::registerMatchers(MatchFinder *
Finder) {
21 if (!getLangOpts().CPlusPlus)
27 anyOf(hasOperatorName(
"+"), hasOperatorName(
"-"),
28 hasOperatorName(
"+="), hasOperatorName(
"-=")),
29 hasType(pointerType()),
30 unless(hasLHS(ignoringImpCasts(declRefExpr(to(isImplicit()))))))
35 unaryOperator(anyOf(hasOperatorName(
"++"), hasOperatorName(
"--")),
36 hasType(pointerType()))
43 hasBase(ignoringImpCasts(
44 anyOf(hasType(pointerType()),
45 hasType(decayedType(hasDecayedType(pointerType())))))))
50 void ProBoundsPointerArithmeticCheck::check(
51 const MatchFinder::MatchResult &Result) {
52 const auto *MatchedExpr = Result.Nodes.getNodeAs<Expr>(
"expr");
54 diag(MatchedExpr->getExprLoc(),
"do not use pointer arithmetic");
std::unique_ptr< ast_matchers::MatchFinder > Finder