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()))
33 void BoolPointerImplicitConversionCheck::check(
34 const MatchFinder::MatchResult &Result) {
35 auto *If = Result.Nodes.getNodeAs<IfStmt>(
"if");
36 auto *Var = Result.Nodes.getNodeAs<DeclRefExpr>(
"expr");
39 if (Var->getLocStart().isMacroID())
47 const Decl *D = Var->getDecl();
48 auto DeclRef = ignoringParenImpCasts(declRefExpr(to(equalsNode(D))));
50 unaryOperator(hasOperatorName(
"*"), hasUnaryOperand(
DeclRef))),
53 !match(findAll(arraySubscriptExpr(hasBase(
DeclRef))), *If,
58 !match(findAll(callExpr(hasAnyArgument(ignoringParenImpCasts(
DeclRef)))),
61 !match(findAll(cxxDeleteExpr(has(ignoringParenImpCasts(expr(
DeclRef))))),
66 diag(Var->getLocStart(),
"dubious check of 'bool *' against 'nullptr', did " 67 "you mean to dereference it?")
68 << FixItHint::CreateInsertion(Var->getLocStart(),
"*");
const DeclRefExpr * DeclRef