<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/147517>147517</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[clang] Rejects-valid enum comparison that bypasses rewritten candidate `<=>`
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
Eisenwave
</td>
</tr>
</table>
<pre>
https://godbolt.org/z/vhxbYPq3j
```cpp
#include <utility>
enum class e { a, b };
inline std::strong_ordering operator<=>(e, e) {
return std::strong_ordering::less;
}
constexpr bool hoo(e lhs, e rhs) {
if (lhs < rhs) {
return true;
}
if (rhs >= lhs) {
return false;
}
return false;
}
static_assert(hoo(e::a, e::b), "");
```
This code fails to compile:
```cpp
<source>:19:15: error: static assertion expression is not an integral constant expression
19 | static_assert(hoo(e::a, e::b), "");
| ^~~~~~~~~~~~~~~
<source>:10:13: note: non-constexpr function 'operator<=>' cannot be used in a constant expression
10 | if (lhs < rhs) {
| ^
<source>:19:15: note: in call to 'hoo(0, 1)'
19 | static_assert(hoo(e::a, e::b), "");
| ^~~~~~~~~~~~~~~
<source>:5:29: note: declared here
5 | inline std::strong_ordering operator<=>(e, e) {
| ^
```
This error is incorrect. GCC accepts.
https://eel.is/c++draft/over.match.best.general#2.8 states that a function is a better candidate if it is rewritten and the other is not, and there exists a built-in candidate for `<` (https://eel.is/c++draft/over.match.oper#3.3, https://eel.is/c++draft/over.built) which would thus be better than the rewritten candidate which uses `(lhs <=> rhs) < 0`.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJy0VsFy4zYM_Rr6golGIiPLOvjg2HGvnU4vPe1QFGRxhyZdEnJ2e-i3dyBq42ST3XanrUcjUSTxgPcAiNYp2ZNH3Ir6QdSHlZ5oDHH7aBP6J33FVRf6z9uR6JKE2gl5FPJ4Cn0XHBUhnoQ8_iHk8Tp-6n77-Xf1UZQ7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