<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/148556>148556</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            Missing suggestion in error message with defaulted three-way comparison when return type is auto
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          jonathanpoelen
      </td>
    </tr>
</table>

<pre>
    When defining a struct that provides at least `==` and `<` operators but not a three-way comparison operator, and using `auto operator<=>(T const&) = default;` in another struct, Clang emits an error indicating that the defaulted operator<=> is implicitly deleted.

```cpp
<source>:15:12: error: object of type 'Item' cannot be compared because its 'operator<=>' is implicitly deleted
   15 |     Item{} < Item{};
      |            ^
<source>:11:10: note: explicitly defaulted function was implicitly deleted here
   11 |     auto operator<=>(const Item &other) const = default;
      |          ^
<source>:9:7: note: defaulted 'operator<=>' is implicitly deleted because there is no viable three-way comparison function for member 'text'
    9 |     A text;
      | ^
```

This message is unclear for users who have correctly implemented `==` and `<`. GCC, in comparison, provides a much more helpful message suggesting to change the return type from `auto` to a comparison category type to allow the comparison to use `operator<` and `operator==`:

```cpp
<source>:11:10: note: changing the return type from 'auto' to a comparison category type will allow the comparison to use 'operator<' and 'operator=='
   11 |     auto operator<=>(const Item &other) const = default;
      |          ^~~~~~~~
```

## Desired Behavior

- Suggest, as GCC does, that changing the return type from `auto` to a comparison category type (e.g., `std::strong_ordering` or `std::partial_ordering`) would allow `operator<=>` to fall back on `operator<` and `operator==`.

## Environment
 
- Clang version: 17, 18, 19, 20

## Code to reproduce

https://godbolt.org/z/6hzfPc7er

```cpp
#include <compare>

struct A {};

bool operator==(A const&, A const&);
bool operator<(A const&, A const&);

struct Item {
    A text;

    auto operator<=>(const Item &other) const = default;
};

int main() {
 Item{} < Item{};
}
```

### Full Clang Output

```cpp
<source>:11:10: warning: explicitly defaulted three-way comparison operator is implicitly deleted [-Wdefaulted-function-deleted]
   11 |     auto operator<=>(const Item &other) const = default;
      |          ^
<source>:9:7: note: defaulted 'operator<=>' is implicitly deleted because there is no viable three-way comparison function for member 'text'
    9 |     A text;
      | ^
<source>:11:49: note: replace 'default' with 'delete'
   11 | auto operator<=>(const Item &other) const = default;
      | ^~~~~~~
      | delete
<source>:15:12: error: object of type 'Item' cannot be compared because its 'operator<=>' is implicitly deleted
   15 | Item{} < Item{};
      |            ^
<source>:11:10: note: explicitly defaulted function was implicitly deleted here
   11 |     auto operator<=>(const Item &other) const = default;
      | ^
<source>:9:7: note: defaulted 'operator<=>' is implicitly deleted because there is no viable three-way comparison function for member 'text'
    9 | A text;
      |       ^
```

### Full Gcc Output 

```cpp
<source>:15:19: error: use of deleted function 'constexpr auto Item::operator<=>(const Item&) const'
   15 |     Item{} < Item{};
      | ^
<source>:11:10: note: 'constexpr auto Item::operator<=>(const Item&) const' is implicitly deleted because the default definition would be ill-formed:
   11 |     auto operator<=>(const Item &other) const = default;
      |          ^~~~~~~~
<source>:9:7: error: no match for 'operator<=>' (operand types are 'A' and 'A')
    9 | A text;
      |       ^~~~
<source>:11:10: note: changing the return type from 'auto' to a comparison category type will allow the comparison to use 'operator<' and 'operator=='
   11 |     auto operator<=>(const Item &other) const = default;
      |          ^~~~~~~~
```
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzsWE2P4jgT_jXmUgIFBwgcOND0MHoPr3alHWmOK8cpEs86dmQ7MD2H_e2rcgIdeqA_Vq390A5CgdiOq56qpz4c4b0qDeKaze_Y_H4k2lBZt_5ijQiVMI1FjWaU2-Jh_blCAwXulVGmBAE-uFYGCJUI0Dh7UAV6EAE0Ch-ALRKW3tN3kYAwRTewpTvboBPBOg95G8DYAAJC5RDHR_EA0taNcMpbc17I-DZu0XqSzBaJaIN9nE23UdIHxpefQFrjA-MLxlfA0ntSWLQ6sPSORCsDwthQoevVp623WpgSsFbBgzCAzlkHyhRKikACI8JQ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