12 using namespace clang::ast_matchers;
18 void BoolPointerImplicitConversionCheck::registerMatchers(MatchFinder *
Finder) {
22 ifStmt(hasCondition(findAll(implicitCastExpr(
23 allOf(unless(hasParent(unaryOperator(hasOperatorName(
"!")))),
24 hasSourceExpression(expr(
25 hasType(pointerType(pointee(booleanType()))),
26 ignoringParenImpCasts(declRefExpr().bind(
"expr")))),
27 hasCastKind(CK_PointerToBoolean))))),
28 unless(isInTemplateInstantiation())).bind(
"if"),
32 void BoolPointerImplicitConversionCheck::check(
33 const MatchFinder::MatchResult &
Result) {
34 auto *If = Result.Nodes.getStmtAs<IfStmt>(
"if");
35 auto *Var = Result.Nodes.getStmtAs<DeclRefExpr>(
"expr");
38 if (Var->getLocStart().isMacroID())
46 const Decl *D = Var->getDecl();
47 auto DeclRef = ignoringParenImpCasts(declRefExpr(to(equalsNode(D))));
49 unaryOperator(hasOperatorName(
"*"), hasUnaryOperand(DeclRef))),
52 !match(findAll(arraySubscriptExpr(hasBase(DeclRef))), *If,
57 !match(findAll(callExpr(hasAnyArgument(ignoringParenImpCasts(DeclRef)))),
60 !match(findAll(cxxDeleteExpr(has(ignoringParenImpCasts(expr(DeclRef))))),
65 diag(Var->getLocStart(),
"dubious check of 'bool *' against 'nullptr', did "
66 "you mean to dereference it?")
67 << FixItHint::CreateInsertion(Var->getLocStart(),
"*");
std::unique_ptr< ast_matchers::MatchFinder > Finder