| 1 |
// Test that most properties of <=> are copied to ==. |
| 2 |
// { dg-do compile { target c++20 } } |
| 3 |
|
| 4 |
#include <compare> |
| 5 |
|
| 6 |
template<typename T> struct X { |
| 7 |
T t; |
| 8 |
friend consteval std::partial_ordering operator<=>(X, X) requires (sizeof(T) != 1) = default; |
| 9 |
// implicitly declares: friend constexpr bool operator==(X, X) requires (sizeof(T) != 1) = default; |
| 10 |
}; |
| 11 |
|
| 12 |
template<typename T> struct Y { |
| 13 |
[[nodiscard]] virtual std::strong_ordering operator<=>(const Y&) const = default; |
| 14 |
// implicitly declares: [[nodiscard]] virtual bool operator==(const Y&) const = default; |
| 15 |
}; |
| 16 |
|
| 17 |
struct Z: Y<int> |
| 18 |
{ |
| 19 |
bool operator==(const Y&) const noexcept override; |
| 20 |
}; |
| 21 |
|
| 22 |
int main() |
| 23 |
{ |
| 24 |
X<char>() == X<char>(); // { dg-error "no match" } |
| 25 |
X<int> x; x == x; // { dg-error "x' is not usable in a constant expression|call to consteval function" } |
| 26 |
Y<int>() == Y<int>(); // { dg-warning "nodiscard" } |
| 27 |
} |