From: Jason Merrill Date: Tue, 26 May 2020 21:27:55 +0000 (-0400) Subject: c++: operator<=> and -Wzero-as-null-pointer-constant [PR95242] X-Git-Tag: releases/gcc-10.2.0~324 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fac77bd88dc450f6bcc8f5945186990c094b5cfc;p=thirdparty%2Fgcc.git c++: operator<=> and -Wzero-as-null-pointer-constant [PR95242] In C++20, if there is no viable operator< available, lhs < rhs gets rewritten to (lhs <=> rhs) < 0, where operator< for the comparison categories is intended to accept literal 0 on the RHS but not other integers. We don't want this to produce a warning from -Wzero-as-null-pointer-constant. gcc/cp/ChangeLog: * call.c (build_new_op_1): Suppress warn_zero_as_null_pointer_constant across comparison of <=> result to 0. gcc/testsuite/ChangeLog: * g++.dg/cpp2a/spaceship-synth2.C: Add -Wzero-as-null-pointer-constant. (cherry picked from commit 6c66c692043d680a5efcd9616b94f9629c417038) --- diff --git a/gcc/cp/call.c b/gcc/cp/call.c index 8345997ccf9a..4a2754bcd1f7 100644 --- a/gcc/cp/call.c +++ b/gcc/cp/call.c @@ -6391,6 +6391,7 @@ build_new_op_1 (const op_location_t &loc, enum tree_code code, int flags, tree rhs = integer_zero_node; if (cand->reversed ()) std::swap (lhs, rhs); + warning_sentinel ws (warn_zero_as_null_pointer_constant); result = build_new_op (loc, code, LOOKUP_NORMAL|LOOKUP_REWRITTEN, lhs, rhs, NULL_TREE, diff --git a/gcc/testsuite/g++.dg/cpp2a/spaceship-synth2.C b/gcc/testsuite/g++.dg/cpp2a/spaceship-synth2.C index cf23c9771e01..a064df72a49f 100644 --- a/gcc/testsuite/g++.dg/cpp2a/spaceship-synth2.C +++ b/gcc/testsuite/g++.dg/cpp2a/spaceship-synth2.C @@ -1,6 +1,9 @@ // Test with only spaceship defaulted. // { dg-do run { target c++2a } } +// Add this warning to test PR c++/95242 +// { dg-additional-options -Wzero-as-null-pointer-constant } + #include struct D