From 2b2bbee3071cee1b03520d9bf0c80c4f0bbe60eb Mon Sep 17 00:00:00 2001 From: David Blaikie Date: Thu, 15 Mar 2012 20:48:26 +0000 Subject: [PATCH] Provide the specific target type in the -Wnull-conversion warning. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@152835 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Basic/DiagnosticSemaKinds.td | 2 +- lib/Sema/SemaChecking.cpp | 2 +- test/SemaCXX/conversion.cpp | 12 ++++++++---- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index b4fd66d592..1efa4f2f17 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -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; def warn_impcast_null_pointer_to_integer : Warning< - "implicit conversion of NULL constant to integer">, + "implicit conversion of NULL constant to %0">, InGroup; def warn_impcast_function_to_bool : Warning< "address of function %q0 will always evaluate to 'true'">, diff --git a/lib/Sema/SemaChecking.cpp b/lib/Sema/SemaChecking.cpp index f00a655f59..cd24a4f459 100644 --- a/lib/Sema/SemaChecking.cpp +++ b/lib/Sema/SemaChecking.cpp @@ -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; } diff --git a/test/SemaCXX/conversion.cpp b/test/SemaCXX/conversion.cpp index d9ba07ab5b..9e0950634d 100644 --- a/test/SemaCXX/conversion.cpp +++ b/test/SemaCXX/conversion.cpp @@ -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'}} } -- 2.40.0