10#include "clang/AST/ASTContext.h"
11#include "clang/AST/ParentMapContext.h"
12#include "clang/ASTMatchers/ASTMatchFinder.h"
13#include "clang/ASTMatchers/ASTMatchers.h"
21 ast_matchers::internal::Matcher<DeclStmt>, InnerMatcher) {
22 for (
const DeclStmt *Stmt : {Node.getBeginStmt(), Node.getEndStmt()})
23 if (Stmt !=
nullptr && InnerMatcher.matches(*Stmt, Finder, Builder))
29 return stmt(hasAncestor(cxxForRangeStmt(
30 hasRangeBeginEndStmt(hasDescendant(equalsNode(&Node))))))
31 .matches(Node, Finder, Builder);
35 ast_matchers::internal::Matcher<Expr>, InnerMatcher) {
36 const Expr *E = &Node;
38 DynTypedNodeList
Parents = Finder->getASTContext().getParents(*E);
44 }
while (isa<ImplicitCastExpr>(E));
46 return InnerMatcher.matches(*E, Finder, Builder);
59 unless(hasParent(arraySubscriptExpr())),
60 unless(hasSourceExpression(predefinedExpr())),
61 unless(hasParentIgnoringImpCasts(explicitCastExpr())),
62 unless(isInsideOfRangeBeginEndStmt()),
63 unless(hasSourceExpression(ignoringParens(stringLiteral()))),
64 unless(hasSourceExpression(ignoringParens(
65 conditionalOperator(hasTrueExpression(stringLiteral()),
66 hasFalseExpression(stringLiteral()))))))
72 const MatchFinder::MatchResult &Result) {
73 const auto *MatchedCast = Result.Nodes.getNodeAs<ImplicitCastExpr>(
"cast");
74 if (MatchedCast->getCastKind() != CK_ArrayToPointerDecay)
77 diag(MatchedCast->getExprLoc(),
"do not implicitly decay an array into a "
78 "pointer; consider using gsl::array_view or "
79 "an explicit cast instead");
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
void registerMatchers(ast_matchers::MatchFinder *Finder) override
AST_MATCHER_P(Stmt, isStatementIdenticalToBoundNode, std::string, ID)
AST_MATCHER(BinaryOperator, isRelationalOperator)