11 #include "clang/AST/ASTContext.h" 12 #include "clang/ASTMatchers/ASTMatchFinder.h" 18 namespace cppcoreguidelines {
22 ast_matchers::internal::Matcher<DeclStmt>, InnerMatcher) {
23 for (
const DeclStmt *Stmt : {Node.getBeginStmt(), Node.getEndStmt()})
24 if (Stmt !=
nullptr && InnerMatcher.matches(*Stmt, Finder, Builder))
30 return stmt(hasAncestor(cxxForRangeStmt(
31 hasRangeBeginEndStmt(hasDescendant(equalsNode(&Node))))))
32 .matches(Node, Finder, Builder);
36 ast_matchers::internal::Matcher<Expr>, InnerMatcher) {
37 const Expr *E = &Node;
39 ASTContext::DynTypedNodeList Parents =
40 Finder->getASTContext().getParents(*E);
41 if (Parents.size() != 1)
43 E = Parents[0].get<Expr>();
46 }
while (isa<ImplicitCastExpr>(E));
48 return InnerMatcher.matches(*E, Finder, Builder);
52 void ProBoundsArrayToPointerDecayCheck::registerMatchers(MatchFinder *Finder) {
53 if (!getLangOpts().CPlusPlus)
62 unless(hasParent(arraySubscriptExpr())),
63 unless(hasParentIgnoringImpCasts(explicitCastExpr())),
64 unless(isInsideOfRangeBeginEndStmt()),
65 unless(hasSourceExpression(ignoringParens(stringLiteral()))))
70 void ProBoundsArrayToPointerDecayCheck::check(
71 const MatchFinder::MatchResult &
Result) {
72 const auto *MatchedCast = Result.Nodes.getNodeAs<ImplicitCastExpr>(
"cast");
73 if (MatchedCast->getCastKind() != CK_ArrayToPointerDecay)
76 diag(MatchedCast->getExprLoc(),
"do not implicitly decay an array into a " 77 "pointer; consider using gsl::array_view or " 78 "an explicit cast instead");
AST_MATCHER(BinaryOperator, isAssignmentOperator)
llvm::Optional< llvm::Expected< tooling::AtomicChanges > > Result
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
AST_MATCHER_P(FunctionDecl, throws, internal::Matcher< Type >, InnerMatcher)