public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/96299] New: Defaulted operator <=> implicitly deleted when a member has operator < and operator == and return type is specified
@ 2020-07-23 14:08 gcc-bugzilla at mysko dot org
  2020-10-07 17:26 ` [Bug c++/96299] " mpolacek at gcc dot gnu.org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: gcc-bugzilla at mysko dot org @ 2020-07-23 14:08 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 96299
           Summary: Defaulted operator <=> implicitly deleted when a
                    member has operator < and operator == and return type
                    is specified
           Product: gcc
           Version: 10.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: gcc-bugzilla at mysko dot org
  Target Milestone: ---

The following sample fails to compile with GCC 10.1 and with trunk as of
2020-07-22.

===================
#include <compare>

struct Legacy
{
  bool operator==(Legacy const&) const;
  bool operator<(Legacy const&) const;
};

struct A
{
  std::strong_ordering operator <=> (A const& other) const = default;
  Legacy l;
};

int main()
{
  A a, b;

  return a < b;    
}
===================

With the following error:
<source>: In function 'int main()':

<source>:19:14: error: use of deleted function 'constexpr std::strong_ordering
A::operator<=>(const A&) const'

   19 |   return a < b;

      |              ^

<source>:11:24: note: 'constexpr std::strong_ordering A::operator<=>(const A&)
const' is implicitly deleted because the default definition would be
ill-formed:

   11 |   std::strong_ordering operator <=> (A const& other) const = default;

      |                        ^~~~~~~~

<source>:11:24: error: no match for 'operator<=>' (operand types are 'Legacy'
and 'Legacy')


>From my understanding of p1186r3
(http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1186r3.html) the code
should be accepted. The GCC standards support table lists p1186r3 as
implemented in GCC 10. According to p1186r3, the defaulted operator <=> should
use the member's < and == operators if the return type is specified
(strong/weak/partial), and should not require a <=> operator for the member.

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2021-05-19 20:17 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-23 14:08 [Bug c++/96299] New: Defaulted operator <=> implicitly deleted when a member has operator < and operator == and return type is specified gcc-bugzilla at mysko dot org
2020-10-07 17:26 ` [Bug c++/96299] " mpolacek at gcc dot gnu.org
2020-11-15  0:44 ` gcc-bugzilla at mysko dot org
2020-12-03 16:39 ` jakub at gcc dot gnu.org
2020-12-08 20:13 ` cvs-commit at gcc dot gnu.org
2020-12-08 20:13 ` jason at gcc dot gnu.org
2021-05-19 20:17 ` cvs-commit at gcc dot gnu.org
2021-05-19 20:17 ` cvs-commit at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).