]> granicus.if.org Git - clang/commitdiff
Provide the specific target type in the -Wnull-conversion warning.
authorDavid Blaikie <dblaikie@gmail.com>
Thu, 15 Mar 2012 20:48:26 +0000 (20:48 +0000)
committerDavid Blaikie <dblaikie@gmail.com>
Thu, 15 Mar 2012 20:48:26 +0000 (20:48 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@152835 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/DiagnosticSemaKinds.td
lib/Sema/SemaChecking.cpp
test/SemaCXX/conversion.cpp

index b4fd66d59258a4d6f363962e73c6938e7fdafe22..1efa4f2f17147ee5e4f3ccf9b63f7089f97a9542 100644 (file)
@@ -1731,7 +1731,7 @@ def warn_impcast_bool_to_null_pointer : Warning<
     "initialization of pointer of type %0 to null from a constant boolean "
     "expression">, InGroup<BoolConversion>;
 def warn_impcast_null_pointer_to_integer : Warning<
-    "implicit conversion of NULL constant to integer">,
+    "implicit conversion of NULL constant to %0">,
     InGroup<NullConversion>;
 def warn_impcast_function_to_bool : Warning<
     "address of function %q0 will always evaluate to 'true'">,
index f00a655f59c480989fcf83a2b1d174582d780b3a..cd24a4f459010f380ac8a455cd533d5709c1e7fa 100644 (file)
@@ -4076,7 +4076,7 @@ void CheckImplicitConversion(Sema &S, Expr *E, QualType T,
   if ((E->isNullPointerConstant(S.Context, Expr::NPC_ValueDependentIsNotNull)
            == Expr::NPCK_GNUNull) && Target->isIntegerType()) {
     S.Diag(E->getExprLoc(), diag::warn_impcast_null_pointer_to_integer)
-        << E->getSourceRange() << clang::SourceRange(CC);
+        << T << E->getSourceRange() << clang::SourceRange(CC);
     return;
   }
 
index d9ba07ab5b5703c4829a5a278e0e3f4e55c250c7..9e0950634dd0e8f3cb8fcaafd8f553c178a6d93c 100644 (file)
@@ -57,11 +57,15 @@ namespace test2 {
 // which is on by default.
 
 void test3() {
-  int a = NULL; // expected-warning {{implicit conversion of NULL constant to integer}}
+  int a = NULL; // expected-warning {{implicit conversion of NULL constant to 'int'}}
   int b;
-  b = NULL; // expected-warning {{implicit conversion of NULL constant to integer}}
+  b = NULL; // expected-warning {{implicit conversion of NULL constant to 'int'}}
   long l = NULL; // FIXME: this should also warn, but currently does not if sizeof(NULL)==sizeof(inttype)
-  int c = ((((NULL)))); // expected-warning {{implicit conversion of NULL constant to integer}}
+  int c = ((((NULL)))); // expected-warning {{implicit conversion of NULL constant to 'int'}}
   int d;
-  d = ((((NULL)))); // expected-warning {{implicit conversion of NULL constant to integer}}
+  d = ((((NULL)))); // expected-warning {{implicit conversion of NULL constant to 'int'}}
+  bool bl = NULL; // FIXME: this should warn but we currently suppress a bunch of conversion-to-bool warnings including this one
+  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'}}
 }