10#include "clang/AST/ASTContext.h"
11#include "clang/ASTMatchers/ASTMatchFinder.h"
21 const auto AllPointerTypes =
22 anyOf(hasType(pointerType()),
24 hasDeducedType(hasUnqualifiedDesugaredType(pointerType())))),
25 hasType(decltypeType(hasUnderlyingType(pointerType()))));
30 hasAnyOperatorName(
"+",
"-",
"+=",
"-="), AllPointerTypes,
31 unless(hasLHS(ignoringImpCasts(declRefExpr(to(isImplicit()))))))
36 unaryOperator(hasAnyOperatorName(
"++",
"--"), hasType(pointerType()))
43 hasBase(ignoringImpCasts(
44 anyOf(AllPointerTypes,
45 hasType(decayedType(hasDecayedType(pointerType())))))))
51 const MatchFinder::MatchResult &Result) {
52 const auto *MatchedExpr = Result.Nodes.getNodeAs<Expr>(
"expr");
54 diag(MatchedExpr->getExprLoc(),
"do not use pointer arithmetic");
DiagnosticBuilder diag(SourceLocation Loc, StringRef Description, DiagnosticIDs::Level Level=DiagnosticIDs::Warning)
Add a diagnostic with the check's name.
const LangOptions & getLangOpts() const
Returns the language options from the context.
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.