]> granicus.if.org Git - clang/commitdiff
Enable -Wnull-conversion for non-integral target types (eg: double).
authorDavid Blaikie <dblaikie@gmail.com>
Tue, 19 Jun 2012 21:19:06 +0000 (21:19 +0000)
committerDavid Blaikie <dblaikie@gmail.com>
Tue, 19 Jun 2012 21:19:06 +0000 (21:19 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@158744 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaChecking.cpp
test/FixIt/fixit.cpp
test/SemaCXX/conversion.cpp

index 41ac77b43be63dad7e1239b6f3ca52a288364349..fff8d80a477ae91c04cc0fbe9b25a792a183842a 100644 (file)
@@ -4279,11 +4279,10 @@ void CheckImplicitConversion(Sema &S, Expr *E, QualType T,
     return;
   }
 
-  if (!Source->isIntegerType() || !Target->isIntegerType())
-    return;
-
   if ((E->isNullPointerConstant(S.Context, Expr::NPC_ValueDependentIsNotNull)
-           == Expr::NPCK_GNUNull) && Target->isIntegerType()) {
+           == Expr::NPCK_GNUNull) && !Target->isAnyPointerType()
+      && !Target->isBlockPointerType() && !Target->isFunctionPointerType()
+      && !Target->isMemberFunctionPointerType()) {
     SourceLocation Loc = E->getSourceRange().getBegin();
     if (Loc.isMacroID())
       Loc = S.SourceMgr.getImmediateExpansionRange(Loc).first;
@@ -4291,9 +4290,11 @@ void CheckImplicitConversion(Sema &S, Expr *E, QualType T,
       S.Diag(Loc, diag::warn_impcast_null_pointer_to_integer)
           << T << clang::SourceRange(CC)
           << FixItHint::CreateReplacement(Loc, S.getFixItZeroLiteralForType(T));
-    return;
   }
 
+  if (!Source->isIntegerType() || !Target->isIntegerType())
+    return;
+
   // TODO: remove this early return once the false positives for constant->bool
   // in templates, macros, etc, are reduced or removed.
   if (Target->isSpecificBuiltinType(BuiltinType::Bool))
index 68ede1e43ba8e19f4b84d9769d832efa78d22345..3eac434a36bd3502bb80b49488632151f6a2a074 100644 (file)
@@ -219,6 +219,7 @@ void Foo::SetBar(Bar bar) { bar_ = bar; } // expected-error {{must use 'enum' ta
 
 #define NULL __null
 char c = NULL; // expected-warning {{implicit conversion of NULL constant to 'char'}}
+double dbl = NULL; // expected-warning {{implicit conversion of NULL constant to 'double'}}
 
 namespace arrow_suggest {
 
index a9efd8c14969cca1e9118ccf3d06506d36e63982..ad6e321dd33c7eb26fb609e14dec7754c35178db 100644 (file)
@@ -69,6 +69,7 @@ void test3() {
   char ch = NULL; // expected-warning {{implicit conversion of NULL constant to 'char'}}
   unsigned char uch = NULL; // expected-warning {{implicit conversion of NULL constant to 'unsigned char'}}
   short sh = NULL; // expected-warning {{implicit conversion of NULL constant to 'short'}}
+  double dbl = NULL; // expected-warning {{implicit conversion of NULL constant to 'double'}}
 
   // Use FileCheck to ensure we don't get any unnecessary macro-expansion notes 
   // (that don't appear as 'real' notes & can't be seen/tested by -verify)