10 #include "clang/AST/ASTContext.h"
11 #include "clang/ASTMatchers/ASTMatchFinder.h"
19 void SizeofContainerCheck::registerMatchers(MatchFinder *Finder) {
21 expr(unless(isInTemplateInstantiation()),
22 expr(sizeOfExpr(has(ignoringParenImpCasts(
23 expr(hasType(hasCanonicalType(hasDeclaration(cxxRecordDecl(
24 matchesName(
"^(::std::|::string)"),
25 unless(matchesName(
"^::std::(bitset|array)$")),
26 hasMethod(cxxMethodDecl(hasName(
"size"),
isPublic(),
30 unless(hasAncestor(binaryOperator(
31 hasAnyOperatorName(
"/",
"%"),
32 hasLHS(ignoringParenCasts(sizeOfExpr(expr()))),
33 hasRHS(ignoringParenCasts(equalsBoundNode(
"sizeof"))))))),
37 void SizeofContainerCheck::check(
const MatchFinder::MatchResult &Result) {
39 Result.Nodes.getNodeAs<UnaryExprOrTypeTraitExpr>(
"sizeof");
42 diag(SizeOf->getBeginLoc(),
"sizeof() doesn't return the size of the "
43 "container; did you mean .size()?");