10 #include "clang/AST/ASTContext.h" 11 #include "clang/ASTMatchers/ASTMatchFinder.h" 17 namespace cppcoreguidelines {
19 void ProBoundsPointerArithmeticCheck::registerMatchers(MatchFinder *Finder) {
20 if (!getLangOpts().CPlusPlus)
23 const auto AllPointerTypes = anyOf(
24 hasType(pointerType()), hasType(autoType(hasDeducedType(pointerType()))),
25 hasType(decltypeType(hasUnderlyingType(pointerType()))));
30 anyOf(hasOperatorName(
"+"), hasOperatorName(
"-"),
31 hasOperatorName(
"+="), hasOperatorName(
"-=")),
33 unless(hasLHS(ignoringImpCasts(declRefExpr(to(isImplicit()))))))
38 unaryOperator(anyOf(hasOperatorName(
"++"), hasOperatorName(
"--")),
39 hasType(pointerType()))
46 hasBase(ignoringImpCasts(
47 anyOf(AllPointerTypes,
48 hasType(decayedType(hasDecayedType(pointerType())))))))
53 void ProBoundsPointerArithmeticCheck::check(
54 const MatchFinder::MatchResult &Result) {
55 const auto *MatchedExpr = Result.Nodes.getNodeAs<Expr>(
"expr");
57 diag(MatchedExpr->getExprLoc(),
"do not use pointer arithmetic");
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//