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)
61 implicitCastExpr(unless(hasParent(arraySubscriptExpr())),
62 unless(hasParentIgnoringImpCasts(explicitCastExpr())),
63 unless(isInsideOfRangeBeginEndStmt()),
64 unless(hasSourceExpression(stringLiteral())))
69 void ProBoundsArrayToPointerDecayCheck::check(
70 const MatchFinder::MatchResult &Result) {
71 const auto *MatchedCast = Result.Nodes.getNodeAs<ImplicitCastExpr>(
"cast");
72 if (MatchedCast->getCastKind() != CK_ArrayToPointerDecay)
75 diag(MatchedCast->getExprLoc(),
"do not implicitly decay an array into a " 76 "pointer; consider using gsl::array_view or " 77 "an explicit cast instead");
AST_MATCHER(BinaryOperator, isAssignmentOperator)
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
AST_MATCHER_P(FunctionDecl, throws, internal::Matcher< Type >, InnerMatcher)