From 5916cfd01b73646934abf404de8528c11b842070 Mon Sep 17 00:00:00 2001 From: Paolo Carlini Date: Mon, 17 Aug 2015 21:40:07 +0000 Subject: [PATCH] re PR c++/67216 (false is still a null pointer constant) /cp 2015-08-17 Paolo Carlini PR c++/67216 * call.c (null_ptr_cst_p): In C++11 return 'false' for 'false'. /testsuite 2015-08-17 Paolo Carlini 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 --- gcc/cp/ChangeLog | 5 +++++ gcc/cp/call.c | 19 +++++++++++++++---- gcc/testsuite/ChangeLog | 10 ++++++++++ gcc/testsuite/g++.dg/cpp0x/nullptr34.C | 17 +++++++++++++++++ gcc/testsuite/g++.dg/cpp0x/pr51313.C | 2 +- gcc/testsuite/g++.dg/warn/Wconversion2.C | 3 ++- .../g++.dg/warn/Wnull-conversion-1.C | 9 ++++++--- gcc/testsuite/g++.old-deja/g++.other/null3.C | 3 ++- 8 files changed, 58 insertions(+), 10 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp0x/nullptr34.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index ca00d03e11d..0bf33c8eb6a 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +2015-08-17 Paolo Carlini + + PR c++/67216 + * call.c (null_ptr_cst_p): In C++11 return 'false' for 'false'. + 2015-08-17 Jason Merrill PR c++/67244 diff --git a/gcc/cp/call.c b/gcc/cp/call.c index 19ddb91e08f..909ac990189 100644 --- a/gcc/cp/call.c +++ b/gcc/cp/call.c @@ -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; } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 93aed719457..2f1ba2532a1 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,13 @@ +2015-08-17 Paolo Carlini + + 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 PR tree-optimization/67221 diff --git a/gcc/testsuite/g++.dg/cpp0x/nullptr34.C b/gcc/testsuite/g++.dg/cpp0x/nullptr34.C new file mode 100644 index 00000000000..2fc70a1dd96 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/nullptr34.C @@ -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); +} diff --git a/gcc/testsuite/g++.dg/cpp0x/pr51313.C b/gcc/testsuite/g++.dg/cpp0x/pr51313.C index eb304ba4480..afd281359c5 100644 --- a/gcc/testsuite/g++.dg/cpp0x/pr51313.C +++ b/gcc/testsuite/g++.dg/cpp0x/pr51313.C @@ -14,5 +14,5 @@ extern ostream cout; int main() { - cout << isdigit(0); + cout << isdigit(0); // { dg-error "invalid conversion" } } diff --git a/gcc/testsuite/g++.dg/warn/Wconversion2.C b/gcc/testsuite/g++.dg/warn/Wconversion2.C index 226dd852b76..d105d922059 100644 --- a/gcc/testsuite/g++.dg/warn/Wconversion2.C +++ b/gcc/testsuite/g++.dg/warn/Wconversion2.C @@ -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 } diff --git a/gcc/testsuite/g++.dg/warn/Wnull-conversion-1.C b/gcc/testsuite/g++.dg/warn/Wnull-conversion-1.C index 84a1d380bb7..d35074417e7 100644 --- a/gcc/testsuite/g++.dg/warn/Wnull-conversion-1.C +++ b/gcc/testsuite/g++.dg/warn/Wnull-conversion-1.C @@ -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" } } diff --git a/gcc/testsuite/g++.old-deja/g++.other/null3.C b/gcc/testsuite/g++.old-deja/g++.other/null3.C index 01071f9297b..ff1d0669b69 100644 --- a/gcc/testsuite/g++.old-deja/g++.other/null3.C +++ b/gcc/testsuite/g++.old-deja/g++.other/null3.C @@ -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 } } -- 2.30.2