Issue |
147517
|
Summary |
[clang] Rejects-valid enum comparison that bypasses rewritten candidate `<=>`
|
Labels |
clang
|
Assignees |
|
Reporter |
Eisenwave
|
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`.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs