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

            Bug ID: 94721
           Summary: C++2a: Three-way comparison operator for function
                    pointers rejected
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: daniel.kruegler at googlemail dot com
  Target Milestone: ---

Using the compiler flags

-Wall -Wextra -std=c++2a -pedantic

the following code example

//------------------
#include <compare>

void foo() {}
void bar() {}

int main()
{
  auto p1 = &foo;
  auto p2 = &bar;
  return (p1 <=> p2) != 0 ? 0 : 1;
}
//------------------

is rejected:

>>>>>>>>>>>>>>>
prog.cc: In function 'int main()':
prog.cc:10:14: error: invalid operands of types 'void (*)()' and 'void (*)()'
to binary 'operator<=>'
   10 |   return (p1 <=> p2) != 0 ? 0 : 1;
      |           ~~ ^~~ ~~
      |           |      |
      |           |      void (*)()
      |           void (*)()
<<<<<<<<<<<<<<<

This code should be accepted, because according to [over.built] p18:

"For every T, where T is [..] a pointer type, there exist candidate operator
functions of the form
  [..]
  R operator<=>(T, T);
where R is the result type specified in 7.6.8."

And 7.6.8 [expr.spaceship] p7 says:

"[..] If two pointer operands p and q compare equal (7.6.10), p <=> q yields
std::strong_ordering::equal; if p and q compare unequal, p <=> q yields
std::strong_ordering::less if q compares greater than p and
std::strong_ordering::greater if p compares greater than q (7.6.9). Otherwise,
the result is unspecified."

Reply via email to