Message ID | 4ECD995D.9080000@oracle.com |
---|---|
State | New |
Headers | show |
On 11/23/2011 08:09 PM, Paolo Carlini wrote: > if (null_test) > { > - tree zero = cp_convert (TREE_TYPE (expr), integer_zero_node); > + tree zero = cp_convert (TREE_TYPE (expr), > + want_pointer ? nullptr_node : integer_zero_node); This ?: is unnecessary; if null_test is true, so is want_pointer. OK just using nullptr_node. Jason
On 11/24/2011 03:58 AM, Jason Merrill wrote: > On 11/23/2011 08:09 PM, Paolo Carlini wrote: >> if (null_test) >> { >> - tree zero = cp_convert (TREE_TYPE (expr), integer_zero_node); >> + tree zero = cp_convert (TREE_TYPE (expr), >> + want_pointer ? nullptr_node : integer_zero_node); > > This ?: is unnecessary; if null_test is true, so is want_pointer. > > OK just using nullptr_node. Thanks, yesterday was a bit tired and didn't noticed the trick with null_test set to error_mark_node a few lines before. Applied. Paolo.
Index: testsuite/g++.dg/warn/Wzero-as-null-pointer-constant-3.C =================================================================== --- testsuite/g++.dg/warn/Wzero-as-null-pointer-constant-3.C (revision 0) +++ testsuite/g++.dg/warn/Wzero-as-null-pointer-constant-3.C (revision 0) @@ -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<C *>(x); + (void) y; + } + + static void bar (B *x) + { + C *y = static_cast<C *>(x); + (void) y; + } +}; Index: cp/class.c =================================================================== --- cp/class.c (revision 181678) +++ cp/class.c (working copy) @@ -338,7 +338,8 @@ 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), + want_pointer ? nullptr_node : integer_zero_node); null_test = fold_build2_loc (input_location, NE_EXPR, boolean_type_node, expr, zero); }