https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99629
Bug ID: 99629
Summary: Misleading diagnostic when looking up rewritten
candidate and failing
Product: gcc
Version: 10.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: barry.revzin at gmail dot com
Target Milestone: ---
>From StackOverflow (https://stackoverflow.com/q/66674463/2069064):
#include <compare>
struct S {};
int operator<=>(S, int) { return 0; }
S operator<=>(S, S) { return {}; }
auto x = S{} < S{};
gcc correctly rejects this code as ill-formed. However, the diagnostic provided
is:
<source>:8:14: error: no match for 'operator<' (operand types are 'S' and
'int')
8 | auto x = S{} < S{};
| ~~~~^~~~~
This is technically correct (in the sense that the compiler should be looking
for, specifically, an operator< between S and 0 and fail because it does not
find such a thing) but it's quite a confusing diagnostic since (a) the
highlighted line is not comparing an S to an int and (b) it sure looks like
from the code that you can compare an S to an int.
It would be nice if the diagnostic somehow made clear that having found
operator<=>(S, S) that it's trying to resolve S{} < S{} as (S{} <=> S{}) < 0
and that subsequent lookup doesn't consider rewritten candidates somehow.
Not especially high priority (I don't expect this to be an especially common
idiom...), more of a nice to have.