11 #include "clang/AST/ASTContext.h" 12 #include "clang/ASTMatchers/ASTMatchFinder.h" 19 return Node.getBeginLoc().isValid();
23 clang::ast_matchers::internal::Matcher<clang::Type>,
25 const clang::Type *TypeNode = Node.getTypePtr();
26 return TypeNode !=
nullptr &&
27 InnerMatcher.matches(*TypeNode, Finder, Builder);
31 return Node.isExternCContext();
40 void AvoidCArraysCheck::registerMatchers(MatchFinder *Finder) {
42 if (!getLangOpts().CPlusPlus11)
46 typeLoc(hasValidBeginLoc(), hasType(arrayType()),
47 unless(anyOf(hasParent(varDecl(isExternC())),
49 hasParent(recordDecl(isExternCContext())))),
50 hasAncestor(functionDecl(isExternC())))))
55 void AvoidCArraysCheck::check(
const MatchFinder::MatchResult &
Result) {
56 const auto *ArrayType = Result.Nodes.getNodeAs<TypeLoc>(
"typeloc");
58 static constexpr llvm::StringLiteral UseArray = llvm::StringLiteral(
59 "do not declare C-style arrays, use std::array<> instead");
60 static constexpr llvm::StringLiteral UseVector = llvm::StringLiteral(
61 "do not declare C VLA arrays, use std::vector<> instead");
63 diag(ArrayType->getBeginLoc(),
64 ArrayType->getTypePtr()->isVariableArrayType() ? UseVector : UseArray);
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)