11 #include "clang/AST/ASTContext.h" 12 #include "clang/ASTMatchers/ASTMatchFinder.h" 18 namespace cppcoreguidelines {
20 void ProBoundsPointerArithmeticCheck::registerMatchers(MatchFinder *Finder) {
21 if (!getLangOpts().CPlusPlus)
24 const auto AllPointerTypes = anyOf(
25 hasType(pointerType()), hasType(autoType(hasDeducedType(pointerType()))),
26 hasType(decltypeType(hasUnderlyingType(pointerType()))));
31 anyOf(hasOperatorName(
"+"), hasOperatorName(
"-"),
32 hasOperatorName(
"+="), hasOperatorName(
"-=")),
34 unless(hasLHS(ignoringImpCasts(declRefExpr(to(isImplicit()))))))
39 unaryOperator(anyOf(hasOperatorName(
"++"), hasOperatorName(
"--")),
40 hasType(pointerType()))
47 hasBase(ignoringImpCasts(
48 anyOf(AllPointerTypes,
49 hasType(decayedType(hasDecayedType(pointerType())))))))
54 void ProBoundsPointerArithmeticCheck::check(
55 const MatchFinder::MatchResult &
Result) {
56 const auto *MatchedExpr = Result.Nodes.getNodeAs<Expr>(
"expr");
58 diag(MatchedExpr->getExprLoc(),
"do not use pointer arithmetic");
llvm::Optional< llvm::Expected< tooling::AtomicChanges > > Result
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//