c++: dependent noexcept-spec on defaulted comparison op [PR96242]
authorPatrick Palka <ppalka@redhat.com>
Sun, 6 Feb 2022 15:47:48 +0000 (10:47 -0500)
committerPatrick Palka <ppalka@redhat.com>
Sun, 6 Feb 2022 15:47:48 +0000 (10:47 -0500)
commit8eb329e963593342855b6072e5692659107337b7
treeb861c67b6cd3240eb26404f2152626924f5cbbf9
parentf9e900ce9b17dc7d3a3809d0b0648ebe529a87c5
c++: dependent noexcept-spec on defaulted comparison op [PR96242]

Here we're failing to instantiate the defaulted comparison op's
explicit dependent noexcept-spec.  The problem is ultimately that
mark_used relies on maybe_instantiate_noexcept to synthesize a defaulted
comparison op, but the relevant DECL_MAYBE_DELETED fn handling in m_i_n
is intended for such functions whose noexcept-spec wasn't explicitly
provided (and is therefore determined via synthesis), so m_i_n just
exits early afterwards, without considering that the synthesized fn may
have an explicit noexcept-spec that needs instantiating.

This patch fixes this issue by making mark_used directly synthesize a
DECL_MAYBE_DELETED fn before calling maybe_instantiate_noexcept.  And
in turn, we can properly restrict the DECL_MAYBE_DELETED fn synthesis
in m_i_n to only those without an explicit noexcept-spec.

PR c++/96242

gcc/cp/ChangeLog:

* decl2.cc (mark_used): Directly synthesize a DECL_MAYBE_DELETED
fn by calling maybe_synthesize_method instead of relying on
maybe_instantiate_noexcept.  Move call to m_i_n after the
DECL_DELETED_FN handling.
* pt.cc (maybe_instantiate_noexcept): Restrict DECL_MAYBE_DELETED
fn synthesis to only those with an implicit noexcept-spec, and
return !DECL_DELETED_FN instead of !DECL_MAYBE_DELETED afterwards.

gcc/testsuite/ChangeLog:

* g++.dg/cpp2a/spaceship-synth15.C: New test.
gcc/cp/decl2.cc
gcc/cp/pt.cc
gcc/testsuite/g++.dg/cpp2a/spaceship-synth15.C [new file with mode: 0644]