10#include "clang/AST/ASTContext.h"
11#include "clang/ASTMatchers/ASTMatchFinder.h"
19 expr(unless(isInTemplateInstantiation()),
20 expr(sizeOfExpr(has(ignoringParenImpCasts(
21 expr(hasType(hasCanonicalType(hasDeclaration(cxxRecordDecl(
22 matchesName(
"^(::std::|::string)"),
23 unless(matchesName(
"^::std::(bitset|array)$")),
24 hasMethod(cxxMethodDecl(hasName(
"size"), isPublic(),
28 unless(hasAncestor(binaryOperator(
29 hasAnyOperatorName(
"/",
"%"),
30 hasLHS(ignoringParenCasts(sizeOfExpr(expr()))),
31 hasRHS(ignoringParenCasts(equalsBoundNode(
"sizeof"))))))),
37 Result.Nodes.getNodeAs<UnaryExprOrTypeTraitExpr>(
"sizeof");
40 diag(SizeOf->getBeginLoc(),
"sizeof() doesn't return the size of the "
41 "container; did you mean .size()?");
DiagnosticBuilder diag(SourceLocation Loc, StringRef Description, DiagnosticIDs::Level Level=DiagnosticIDs::Warning)
Add a diagnostic with the check's name.
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Override this to register AST matchers with Finder.
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
ClangTidyChecks that register ASTMatchers should do the actual work in here.