diff options
author | Jason Merrill <jason@redhat.com> | 2020-05-26 17:27:55 -0400 |
---|---|---|
committer | Giuliano Belinassi <giuliano.belinassi@usp.br> | 2020-08-17 13:09:07 -0300 |
commit | b05214c6b757b555330dbcd8a72cb92c8f27954c (patch) | |
tree | 167bf284daf9d4d33903798994263e17b51701ea | |
parent | 9a1f6add5e2a3d04930d693468494aeb9015d68a (diff) | |
download | gcc-b05214c6b757b555330dbcd8a72cb92c8f27954c.zip gcc-b05214c6b757b555330dbcd8a72cb92c8f27954c.tar.gz gcc-b05214c6b757b555330dbcd8a72cb92c8f27954c.tar.bz2 |
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.
-rw-r--r-- | gcc/cp/call.c | 1 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/cpp2a/spaceship-synth2.C | 3 |
2 files changed, 4 insertions, 0 deletions
diff --git a/gcc/cp/call.c b/gcc/cp/call.c index d858288..a51ebb5 100644 --- a/gcc/cp/call.c +++ b/gcc/cp/call.c @@ -6410,6 +6410,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 e6401d2..9b6cfa0 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++20 } } +// Add this warning to test PR c++/95242 +// { dg-additional-options -Wzero-as-null-pointer-constant } + #include <compare> struct D |