https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99628
Bug ID: 99628
Summary: g++ fails to do the implicit conversion when rewritten
operator<=>
Product: gcc
Version: 11.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: hewillk at gmail dot com
Target Milestone: ---
gcc-trunk rejects this valid code:
struct S{
operator int() { return 0; }
};
auto operator<=>(S, S) { return S{}; }
int main() {
return S{} < S{};
}
(godbolt://godbolt.org/z/9ah1xE)
The expression S{} < S{} would be rewritten as (S{} <=> S{}) < 0, since the
(S{} <=> S{}) return S{}, we compare S{} with 0, and S{} explicit convert to 0,
so we compare 0 < 0 which is false, but gcc-trunk rejects with:
<source>:8:14: error: no match for 'operator<' (operand types are 'S' and
'int')
8 | return S{} < S{};