From 36b0e7519f8e86d3fa5df495fce260874ebbcbb2 Mon Sep 17 00:00:00 2001 From: Paolo Carlini Date: Thu, 24 Nov 2011 10:20:43 +0000 Subject: [PATCH] re PR c++/51290 (Bogus warning: zero as null pointer constant with static_cast) /cp 2011-11-24 Paolo Carlini PR c++/51290 * class.c (build_base_path): For the null pointer check use nullptr_node instead of integer_zero_node. /testsuite 2011-11-24 Paolo Carlini PR c++/51290 * g++.dg/warn/Wzero-as-null-pointer-constant-3.C: New. From-SVN: r181690 --- gcc/cp/ChangeLog | 6 +++++ gcc/cp/class.c | 2 +- gcc/testsuite/ChangeLog | 5 +++++ .../warn/Wzero-as-null-pointer-constant-3.C | 22 +++++++++++++++++++ 4 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/warn/Wzero-as-null-pointer-constant-3.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 6833fc390f2..83a5508c169 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2011-11-24 Paolo Carlini + + PR c++/51290 + * class.c (build_base_path): For the null pointer check use + nullptr_node instead of integer_zero_node. + 2011-11-22 Dodji Seketeli PR c++/51145 diff --git a/gcc/cp/class.c b/gcc/cp/class.c index cb0e683c597..3cb76de60aa 100644 --- a/gcc/cp/class.c +++ b/gcc/cp/class.c @@ -338,7 +338,7 @@ build_base_path (enum tree_code code, /* Now that we've saved expr, build the real null test. */ if (null_test) { - tree zero = cp_convert (TREE_TYPE (expr), integer_zero_node); + tree zero = cp_convert (TREE_TYPE (expr), nullptr_node); null_test = fold_build2_loc (input_location, NE_EXPR, boolean_type_node, expr, zero); } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 4be809d22d2..5674c281ac3 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2011-11-24 Paolo Carlini + + PR c++/51290 + * g++.dg/warn/Wzero-as-null-pointer-constant-3.C: New. + 2011-11-23 Jakub Jelinek PR target/51261 diff --git a/gcc/testsuite/g++.dg/warn/Wzero-as-null-pointer-constant-3.C b/gcc/testsuite/g++.dg/warn/Wzero-as-null-pointer-constant-3.C new file mode 100644 index 00000000000..ed54143a027 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wzero-as-null-pointer-constant-3.C @@ -0,0 +1,22 @@ +// PR c++/51290 +// { dg-options "-Wzero-as-null-pointer-constant" } + +class A { int a; }; + +class B { int b; }; + +class C : public A, public B +{ + private: + static void foo (A *x) + { + C *y = static_cast(x); + (void) y; + } + + static void bar (B *x) + { + C *y = static_cast(x); + (void) y; + } +}; -- 2.30.2