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

            Bug ID: 115909
           Summary: C++20 operator<=> explicitly defaulted but defined as
                    deleted after first declaration does not error
           Product: gcc
           Version: 15.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: mital at mitalashok dot co.uk
  Target Milestone: ---

When a function is defined as deleted (even if it was explicitly defaulted), it
must be the first declaration
<https://eel.is/c++draft/dcl.fct.def.delete#4.sentence-3>.

However, GCC doesn't appear to issue an error when this happens for a
operator<=>.

https://godbolt.org/z/KseW3r8EW

```
namespace std {
  struct strong_ordering { static const strong_ordering less, equal, greater;
};
}
struct X {
  X(int);
};
struct Y {
  X x;
  Y();
  friend auto operator<=>(Y, Y);
};
struct Z {
  X x;
  auto operator<=>(const Z&) const;
};
// Y::Y() = default;
auto operator<=>(Y, Y) = default;
auto Z::operator<=>(const Z&) const = default;
```

Y::Y() is rejected as expected when uncommented (although the error could use a
little work? It should say something like "error: deleted definition must be
the first declaration"), but with the comment this compiles without any
diagnostics.

If you replace the `= default` with `= delete`, this compiles with a warning
only when it should error (Which is Bug 52659 I think)

Possibly related: Bug 103947

Reply via email to