Kind = CK_BitCast;
- if (CXXBoolLiteralExpr* LitBool
- = dyn_cast<CXXBoolLiteralExpr>(From->IgnoreParens()))
- if (!IsCStyleOrFunctionalCast && LitBool->getValue() == false)
- DiagRuntimeBehavior(LitBool->getExprLoc(), From,
- PDiag(diag::warn_init_pointer_from_false) << ToType);
+ if (!IsCStyleOrFunctionalCast &&
+ Context.hasSameUnqualifiedType(From->getType(), Context.BoolTy) &&
+ From->isNullPointerConstant(Context, Expr::NPC_ValueDependentIsNotNull))
+ DiagRuntimeBehavior(From->getExprLoc(), From,
+ PDiag(diag::warn_init_pointer_from_false) << ToType);
if (const PointerType *FromPtrType = FromType->getAs<PointerType>())
if (const PointerType *ToPtrType = ToType->getAs<PointerType>()) {
void foo(int* i, int *j=(false)) // expected-warning{{ initialization of pointer of type 'int *' from literal 'false'}}
{
foo(false); // expected-warning{{ initialization of pointer of type 'int *' from literal 'false'}}
- foo((int*)false);
+ foo((int*)false); // no-warning: explicit cast
+ foo(0); // no-warning: not a bool, even though its convertible to bool
+
+ foo(false == true); // expected-warning{{ initialization of pointer of type 'int *' from literal 'false'}}
+ foo((42 + 24) < 32); // expected-warning{{ initialization of pointer of type 'int *' from literal 'false'}}
+
+ const bool kFlag = false;
+ foo(kFlag); // expected-warning{{ initialization of pointer of type 'int *' from literal 'false'}}
}
char f(struct Undefined*);