https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118387

--- Comment #9 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jakub Jelinek <ja...@gcc.gnu.org>:

https://gcc.gnu.org/g:18f6bb9899209ccd41c476254d30596606c81dd7

commit r15-6909-g18f6bb9899209ccd41c476254d30596606c81dd7
Author: Jakub Jelinek <ja...@redhat.com>
Date:   Wed Jan 15 08:56:40 2025 +0100

    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  <ja...@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.

Reply via email to