https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116335
Bug ID: 116335
Summary: defaulting int spaceship operator produces wrong code
Product: gcc
Version: 14.2.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: fchelnokov at gmail dot com
Target Milestone: ---
This program
```
struct A {
int x = 0;
constexpr int operator<=>(const A & r) const { return x - r.x; }
};
// ok everywhere
static_assert( A{1} < A{2} );
static_assert( A{1} >= A{1} );
struct B {
A u, v;
int operator<=>(const B &) const = default;
};
// ok in GCC
static_assert( B{{1},{2}} < B{{2},{1}} );
static_assert( B{{1},{2}} < B{{1},{3}} );
int main() {
return B{{1},{2}} >= B{{1},{2}};
}
```
is accepted by GCC without warnings, but resulting program crashes (SIGILL
or SIGSEGV). Online demo: https://gcc.godbolt.org/z/11he8PeT1
Probably, defaulting operator<=> with int return type (and other not-standard
types) shall be rejected during compilation.