From: Argyrios Kyrtzidis Date: Tue, 28 Sep 2010 14:54:11 +0000 (+0000) Subject: Don't warn with -Wbool-conversions if the user wrote an explicit cast like "(void... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b3358724d985dc08889f7905f20284718361e885;p=clang Don't warn with -Wbool-conversions if the user wrote an explicit cast like "(void *)false". Fixes rdar://8459342. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@114955 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaOverload.cpp b/lib/Sema/SemaOverload.cpp index a7e5e3ae71..919aea8d02 100644 --- a/lib/Sema/SemaOverload.cpp +++ b/lib/Sema/SemaOverload.cpp @@ -1728,10 +1728,11 @@ bool Sema::CheckPointerConversion(Expr *From, QualType ToType, CXXCastPath& BasePath, bool IgnoreBaseAccess) { QualType FromType = From->getType(); + bool IsCStyleOrFunctionalCast = IgnoreBaseAccess; if (CXXBoolLiteralExpr* LitBool = dyn_cast(From->IgnoreParens())) - if (LitBool->getValue() == false) + if (!IsCStyleOrFunctionalCast && LitBool->getValue() == false) Diag(LitBool->getExprLoc(), diag::warn_init_pointer_from_false) << ToType; diff --git a/test/SemaCXX/warn_false_to_pointer.cpp b/test/SemaCXX/warn_false_to_pointer.cpp index 3a873d886f..fb6f9551a7 100644 --- a/test/SemaCXX/warn_false_to_pointer.cpp +++ b/test/SemaCXX/warn_false_to_pointer.cpp @@ -5,5 +5,6 @@ int* j = false; // expected-warning{{ initialization of pointer of type 'int *' 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); }