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 return llvm::any_of(llvm::ArrayRef{Node.getBeginStmt(), Node.getEndStmt()},
23 [&](
const DeclStmt *Stmt) {
25 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 const DynTypedNodeList
Parents = Finder->getASTContext().getParents(*E);
45 }
while (isa<ImplicitCastExpr>(E));
47 return InnerMatcher.matches(*E, Finder, Builder);
60 unless(hasParent(arraySubscriptExpr())),
61 unless(hasSourceExpression(predefinedExpr())),
62 unless(hasParentIgnoringImpCasts(explicitCastExpr())),
63 unless(isInsideOfRangeBeginEndStmt()),
64 unless(hasSourceExpression(ignoringParens(stringLiteral()))),
65 unless(hasSourceExpression(ignoringParens(
66 conditionalOperator(hasTrueExpression(stringLiteral()),
67 hasFalseExpression(stringLiteral()))))))
73 const MatchFinder::MatchResult &Result) {
74 const auto *MatchedCast = Result.Nodes.getNodeAs<ImplicitCastExpr>(
"cast");
75 if (MatchedCast->getCastKind() != CK_ArrayToPointerDecay)
78 diag(MatchedCast->getExprLoc(),
"do not implicitly decay an array into a "
79 "pointer; consider using gsl::array_view or "
80 "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)