11 #include "clang/AST/ASTContext.h" 12 #include "clang/ASTMatchers/ASTMatchFinder.h" 20 void SizeofContainerCheck::registerMatchers(MatchFinder *Finder) {
22 expr(unless(isInTemplateInstantiation()),
23 expr(sizeOfExpr(has(ignoringParenImpCasts(
24 expr(hasType(hasCanonicalType(hasDeclaration(cxxRecordDecl(
25 matchesName(
"^(::std::|::string)"),
26 unless(matchesName(
"^::std::(bitset|array)$")),
27 hasMethod(cxxMethodDecl(hasName(
"size"),
isPublic(),
31 unless(hasAncestor(binaryOperator(
32 anyOf(hasOperatorName(
"/"), hasOperatorName(
"%")),
33 hasLHS(ignoringParenCasts(sizeOfExpr(expr()))),
34 hasRHS(ignoringParenCasts(equalsBoundNode(
"sizeof"))))))),
38 void SizeofContainerCheck::check(
const MatchFinder::MatchResult &
Result) {
40 Result.Nodes.getNodeAs<UnaryExprOrTypeTraitExpr>(
"sizeof");
43 diag(SizeOf->getBeginLoc(),
"sizeof() doesn't return the size of the " 44 "container; did you mean .size()?");
llvm::Optional< llvm::Expected< tooling::AtomicChanges > > Result
static bool isPublic(const clang::AccessSpecifier AS, const clang::Linkage Link)
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//