c++: Delete defaulted operator <=> if std::strong_ordering::equal doesn't...
c++: Delete defaulted operator <=> if std::strong_ordering::equal doesn't convert to its rettype [PR118387] Note, the PR raises another problem. If on the same testcase the B b; line is removed, we silently synthetize operator<=> which will crash at runtime due to returning without a return statement. That is because the standard says that in that case it should return static_cast<int>(std::strong_ordering::equal); but I can't find anywhere wording which would say that if that isn't valid, the function is deleted. https://eel.is/c++draft/class.compare#class.spaceship-2.2 seems to talk just about cases where there are some members and their comparison is invalid it is deleted, but here there are none and it follows https://eel.is/c++draft/class.compare#class.spaceship-3.sentence-2 So, we synthetize with tf_none, see the static_cast is invalid, don't add error_mark_node statement silently, but as the function isn't deleted, we just silently emit it. Should the standard be amended to say that the operator should be deleted even if it has no elements and the static cast from https://eel.is/c++draft/class.compare#class.spaceship-3.sentence-2 On Fri, Jan 10, 2025 at 12:04:53PM -0500, Jason Merrill wrote: > That seems pretty obviously what we want, and is what the other compilers > implement. This patch implements it then. 2025-01-15 Jakub Jelinek <jakub@redhat.com> PR c++/118387 * method.cc (build_comparison_op): Set bad if std::strong_ordering::equal doesn't convert to rettype. * g++.dg/cpp2a/spaceship-err6.C: Expect another error. * g++.dg/cpp2a/spaceship-synth17.C: Likewise. * g++.dg/cpp2a/spaceship-synth-neg6.C: Likewise. * g++.dg/cpp2a/spaceship-synth-neg7.C: New test. * testsuite/25_algorithms/default_template_value.cc (Input::operator<=>): Use auto as return type rather than bool.
Showing
- gcc/cp/method.cc 13 additions, 13 deletionsgcc/cp/method.cc
- gcc/testsuite/g++.dg/cpp2a/spaceship-err6.C 1 addition, 1 deletiongcc/testsuite/g++.dg/cpp2a/spaceship-err6.C
- gcc/testsuite/g++.dg/cpp2a/spaceship-synth-neg6.C 1 addition, 1 deletiongcc/testsuite/g++.dg/cpp2a/spaceship-synth-neg6.C
- gcc/testsuite/g++.dg/cpp2a/spaceship-synth-neg7.C 58 additions, 0 deletionsgcc/testsuite/g++.dg/cpp2a/spaceship-synth-neg7.C
- gcc/testsuite/g++.dg/cpp2a/spaceship-synth17.C 1 addition, 1 deletiongcc/testsuite/g++.dg/cpp2a/spaceship-synth17.C
- libstdc++-v3/testsuite/25_algorithms/default_template_value.cc 1 addition, 1 deletion...dc++-v3/testsuite/25_algorithms/default_template_value.cc
Loading
Please register or sign in to comment