'What's the reason an exactly matched default comparison operator function is deleted?

Consider this example

struct C {
 bool operator<(const C&) const = default; // #1
};
int main(){
   C c1,c2;
  auto r =  c1 < c2;
}

GCC and Clang report that candidate #1 is implicitly deleted.

GCC:

'bool C::operator<(const C&) const' is implicitly deleted because the default definition would be ill-formed

Clang:

defaulted 'operator<' is implicitly deleted because there is no viable three-way comparison function for 'C'

I'm not sure what the concrete reason is here. Specifically, the reason may be laid in [class.compare.secondary]

The operator function with parameters x and y is defined as deleted if

  1. overload resolution ([over.match]), as applied to x @ y, does not result in a usable candidate, or
  2. the candidate selected by overload resolution is not a rewritten candidate.

Otherwise, the operator function yields x @ y. The defaulted operator function is not considered as a candidate in the overload resolution for the @ operator.

The confusion is which bullet determines that the default operator < is deleted. If we ignore the emphasized wording, I think the reason may be the second bullet, since #1 is not a rewritten candidate for x < y. However, if we consider the emphasized wording, #1 will not be a viable candidate since it is a defaulted operator function, thus overload resolution applied to x @ y does not result in a usable candidate.

So, which rule actually determines that candidate #1 is implicitly deleted?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source