Provide the specific target type in the -Wnull-conversion warning.

llvm-svn: 152835
This commit is contained in:
David Blaikie 2012-03-15 20:48:26 +00:00
parent d74560b170
commit e7fd58006d
3 changed files with 10 additions and 6 deletions

View 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 " "initialization of pointer of type %0 to null from a constant boolean "
"expression">, InGroup<BoolConversion>; "expression">, InGroup<BoolConversion>;
def warn_impcast_null_pointer_to_integer : Warning< def warn_impcast_null_pointer_to_integer : Warning<
"implicit conversion of NULL constant to integer">, "implicit conversion of NULL constant to %0">,
InGroup<NullConversion>; InGroup<NullConversion>;
def warn_impcast_function_to_bool : Warning< def warn_impcast_function_to_bool : Warning<
"address of function %q0 will always evaluate to 'true'">, "address of function %q0 will always evaluate to 'true'">,

View File

@ -4076,7 +4076,7 @@ void CheckImplicitConversion(Sema &S, Expr *E, QualType T,
if ((E->isNullPointerConstant(S.Context, Expr::NPC_ValueDependentIsNotNull) if ((E->isNullPointerConstant(S.Context, Expr::NPC_ValueDependentIsNotNull)
== Expr::NPCK_GNUNull) && Target->isIntegerType()) { == Expr::NPCK_GNUNull) && Target->isIntegerType()) {
S.Diag(E->getExprLoc(), diag::warn_impcast_null_pointer_to_integer) S.Diag(E->getExprLoc(), diag::warn_impcast_null_pointer_to_integer)
<< E->getSourceRange() << clang::SourceRange(CC); << T << E->getSourceRange() << clang::SourceRange(CC);
return; return;
} }

View File

@ -57,11 +57,15 @@ namespace test2 {
// which is on by default. // which is on by default.
void test3() { 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; 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) 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; 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'}}
} }