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

            Bug ID: 96489
           Summary: Three way comparison operator failure to synthesize
                    traditional comparitors
           Product: gcc
           Version: 10.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: gu...@henkel-wallace.org
  Target Milestone: ---

User-defined <=> doesn't generate == or != though user-defined operator== and
operator<=> = default do.

/usr/local/opt/gcc/bin/g++-10   -std=c++20 foo.cc && ./a.out
foo.cc: In function 'int main()':
foo.cc:21:9: error: no match for 'operator!=' (operand types are 'foo' and
'foo')
   21 |   if (a != b) std::cout << "not ";
      |       ~ ^~ ~
      |       |    |
      |       foo  foo
foo.cc:25:11: error: no match for 'operator==' (operand types are 'foo' and
'foo')
   25 |   if (!(a == c)) std::cout << "not ";
      |         ~ ^~ ~
      |         |    |
      |         foo  foo

#include <iostream>

struct foo {
    int content;
    foo(int x) : content { x } {}

  // works: auto operator <=> (foo const& rhs) const = default;
  // works: auto operator ==  (foo const& rhs) const { return content == 
rhs.content; }
  // fails: 
            auto operator <=> (foo const& rhs) const { return content <=>
rhs.content; }
};

int main() {
  foo a { 1 };
  foo b { 2 };
  foo c { 1 };

  if (a != b) std::cout << "not ";
  std::cout  << "equal" << std::endl;


  if (!(a == c)) std::cout << "not ";
  std::cout  << "equal" << std::endl;

  return 0;

Result:

/usr/local/opt/gcc/bin/g++-10   -std=c++20 foo.cc && ./a.out
foo.cc: In function 'int main()':
foo.cc:21:9: error: no match for 'operator!=' (operand types are 'foo' and
'foo')
   21 |   if (a != b) std::cout << "not ";
      |       ~ ^~ ~
      |       |    |
      |       foo  foo
foo.cc:25:11: error: no match for 'operator==' (operand types are 'foo' and
'foo')
   25 |   if (!(a == c)) std::cout << "not ";
      |         ~ ^~ ~
      |         |    |
      |         foo  foo

Reply via email to