22 hasCondition(findAll(implicitCastExpr(
23 unless(hasParent(unaryOperator(hasOperatorName(
"!")))),
24 hasSourceExpression(expr(
25 hasType(pointerType(pointee(booleanType()))),
26 ignoringParenImpCasts(anyOf(declRefExpr().bind(
"expr"),
27 memberExpr().bind(
"expr"))))),
28 hasCastKind(CK_PointerToBoolean)))),
29 unless(isInTemplateInstantiation()))
34static void checkImpl(
const MatchFinder::MatchResult &Result,
const Expr *Ref,
36 const ast_matchers::internal::Matcher<Expr> &RefMatcher,
39 if (Ref->getBeginLoc().isMacroID())
47 if (!match(findAll(unaryOperator(hasOperatorName(
"*"),
48 hasUnaryOperand(RefMatcher))),
51 !match(findAll(arraySubscriptExpr(hasBase(RefMatcher))), *If,
57 findAll(callExpr(hasAnyArgument(ignoringParenImpCasts(RefMatcher)))),
61 findAll(cxxDeleteExpr(has(ignoringParenImpCasts(expr(RefMatcher))))),
66 Check.diag(Ref->getBeginLoc(),
67 "dubious check of 'bool *' against 'nullptr', did "
68 "you mean to dereference it?")
69 << FixItHint::CreateInsertion(Ref->getBeginLoc(),
"*");
73 const MatchFinder::MatchResult &Result) {
74 const auto *If = Result.Nodes.getNodeAs<IfStmt>(
"if");
75 if (
const auto *
E = Result.Nodes.getNodeAs<Expr>(
"expr")) {
76 const Decl *D = isa<DeclRefExpr>(
E) ? cast<DeclRefExpr>(
E)->getDecl()
77 : cast<MemberExpr>(
E)->getMemberDecl();
79 ignoringParenImpCasts(anyOf(declRefExpr(to(equalsNode(D))),
80 memberExpr(hasDeclaration(equalsNode(D)))));
const FunctionDecl * Decl
const google::protobuf::Message & M
Base class for all clang-tidy checks.
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.
static void checkImpl(const MatchFinder::MatchResult &Result, const Expr *Ref, const IfStmt *If, const ast_matchers::internal::Matcher< Expr > &RefMatcher, ClangTidyCheck &Check)