From: Jason Merrill Date: Tue, 12 May 2026 15:27:29 +0000 (-0400) Subject: c++: -Wzero-as-null-pointer-constant and <=> [PR100903] X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=03bf757085091d95a9fe4ab964ee62da157ef563;p=thirdparty%2Fgcc.git c++: -Wzero-as-null-pointer-constant and <=> [PR100903] (x <=> y) < 0 is the pattern suggested by the standard, we shouldn't warn about it because of our implementation strategy. We already disable the warning in to avoid warnings on the uses of this pattern within the header, so no library changes are needed. PR c++/100903 gcc/cp/ChangeLog: * call.cc (build_over_call): Avoid -Wzero-as-null-pointer-constant if the warning is disabled around the called function. gcc/testsuite/ChangeLog: * g++.dg/cpp2a/spaceship-warn1.C: New test. --- diff --git a/gcc/cp/call.cc b/gcc/cp/call.cc index 92c3a23ab8d..97cb0d6f012 100644 --- a/gcc/cp/call.cc +++ b/gcc/cp/call.cc @@ -10715,10 +10715,18 @@ build_over_call (struct z_candidate *cand, int flags, tsubst_flags_t complain) func(NULL); } */ - bool const conversion_warning = !(null_node_p (current_arg) - && DECL_TEMPLATE_INFO (fn) - && cand->template_decl - && !cand->explicit_targs); + bool conversion_warning = !(null_node_p (current_arg) + && DECL_TEMPLATE_INFO (fn) + && cand->template_decl + && !cand->explicit_targs); + + /* Also don't warn about (x <=> y) < 0 (c++/100903). */ + if (conversion_warning + && integer_zerop (current_arg) + && warn_zero_as_null_pointer_constant + && !warning_enabled_at (DECL_SOURCE_LOCATION (fn), + OPT_Wzero_as_null_pointer_constant)) + conversion_warning = false; tsubst_flags_t const arg_complain = conversion_warning ? complain : complain & ~tf_warning; diff --git a/gcc/testsuite/g++.dg/cpp2a/spaceship-warn1.C b/gcc/testsuite/g++.dg/cpp2a/spaceship-warn1.C new file mode 100644 index 00000000000..998abef6543 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/spaceship-warn1.C @@ -0,0 +1,10 @@ +// PR c++/100903 +// { dg-additional-options -Wzero-as-null-pointer-constant } +// { dg-do compile { target c++20 } } + +#include + +int main() +{ + return (1.0 <=> 2.0) < 0; +}