re PR c++/67216 (false is still a null pointer constant)

/cp
2015-08-17  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/67216
	* call.c (null_ptr_cst_p): In C++11 return 'false' for 'false'.

/testsuite
2015-08-17  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/67216
	* g++.dg/cpp0x/nullptr34.C: New.
	* g++.dg/warn/Wconversion2.C: Adjust.
	* g++.dg/warn/Wnull-conversion-1.C: Likewise.
	* g++.old-deja/g++.other/null3.C: Likewise.

	* g++.dg/cpp0x/pr51313.C: Adjust.

From-SVN: r226956
This commit is contained in:
Paolo Carlini 2015-08-17 21:40:07 +00:00 committed by Paolo Carlini
parent b361a15ff6
commit 5916cfd01b
8 changed files with 58 additions and 10 deletions

View file

@ -1,3 +1,8 @@
2015-08-17 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/67216
* call.c (null_ptr_cst_p): In C++11 return 'false' for 'false'.
2015-08-17 Jason Merrill <jason@redhat.com>
PR c++/67244

View file

@ -524,22 +524,33 @@ struct z_candidate {
bool
null_ptr_cst_p (tree t)
{
tree type = TREE_TYPE (t);
/* [conv.ptr]
A null pointer constant is an integral constant expression
(_expr.const_) rvalue of integer type that evaluates to zero or
an rvalue of type std::nullptr_t. */
if (NULLPTR_TYPE_P (TREE_TYPE (t)))
if (NULLPTR_TYPE_P (type))
return true;
if (CP_INTEGRAL_TYPE_P (TREE_TYPE (t)))
if (cxx_dialect >= cxx11)
{
/* Core issue 903 says only literal 0 is a null pointer constant. */
if (cxx_dialect < cxx11)
t = fold_non_dependent_expr (t);
if (TREE_CODE (type) == INTEGER_TYPE
&& TREE_CODE (t) == INTEGER_CST
&& integer_zerop (t)
&& !TREE_OVERFLOW (t))
return true;
}
else if (CP_INTEGRAL_TYPE_P (type))
{
t = fold_non_dependent_expr (t);
STRIP_NOPS (t);
if (integer_zerop (t) && !TREE_OVERFLOW (t))
return true;
}
return false;
}

View file

@ -1,3 +1,13 @@
2015-08-17 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/67216
* g++.dg/cpp0x/nullptr34.C: New.
* g++.dg/warn/Wconversion2.C: Adjust.
* g++.dg/warn/Wnull-conversion-1.C: Likewise.
* g++.old-deja/g++.other/null3.C: Likewise.
* g++.dg/cpp0x/pr51313.C: Adjust.
2015-08-17 Richard Biener <rguenther@suse.de>
PR tree-optimization/67221

View file

@ -0,0 +1,17 @@
// PR c++/67216
// { dg-do compile { target c++11 } }
struct s {
s( long ) {}
};
struct t {
t( void * ) {}
};
void foo(s) {}
void foo(t) {}
int main() {
foo(false);
}

View file

@ -14,5 +14,5 @@ extern ostream cout;
int main()
{
cout << isdigit(0);
cout << isdigit(0); // { dg-error "invalid conversion" }
}

View file

@ -1,3 +1,4 @@
// { dg-options "-Wconversion-null" }
void foo(const char *);
void bar() { foo(false); } // { dg-warning "pointer type for argument" }
void bar() { foo(false); } // { dg-warning "pointer type for argument" "" { target { ! c++11 } } }
// { dg-error "cannot convert" "" { target c++11 } 3 }

View file

@ -6,10 +6,13 @@
void func1(int* ptr);
void func2() {
int* t = false; // { dg-warning "converting 'false' to pointer" }
int* t = false; // { dg-warning "converting 'false' to pointer" "" { target { ! c++11 } } }
// { dg-error "cannot convert" "" { target c++11 } 9 }
int* p;
p = false; // { dg-warning "converting 'false' to pointer" }
p = false; // { dg-warning "converting 'false' to pointer" "" { target { ! c++11 } } }
// { dg-error "cannot convert" "" { target c++11 } 12 }
int* r = sizeof(char) / 2; // { dg-error "invalid conversion from" "" { target c++11 } }
func1(false); // { dg-warning "converting 'false' to pointer" }
func1(false); // { dg-warning "converting 'false' to pointer" "" { target { ! c++11 } } }
// { dg-error "cannot convert" "" { target c++11 } 15 }
int i = NULL; // { dg-warning "converting to non-pointer" }
}

View file

@ -2,5 +2,6 @@
void x()
{
int* p = 1==0; // { dg-warning "converting 'false' to pointer" }
int* p = 1==0; // { dg-warning "converting 'false' to pointer" "" { target { ! c++11 } } }
// { dg-error "cannot convert" "" { target c++11 } 5 }
}