| 1 |
// RUN: %clang_cc1 -fsyntax-only -verify %s -Wzero-as-null-pointer-constant -std=c++20 |
| 2 |
|
| 3 |
namespace std { |
| 4 |
class strong_ordering; |
| 5 |
|
| 6 |
// Mock how STD defined unspecified parameters for the operators below. |
| 7 |
struct _CmpUnspecifiedParam { |
| 8 |
consteval |
| 9 |
_CmpUnspecifiedParam(int _CmpUnspecifiedParam::*) noexcept {} |
| 10 |
}; |
| 11 |
|
| 12 |
struct strong_ordering { |
| 13 |
signed char value; |
| 14 |
|
| 15 |
friend constexpr bool operator==(strong_ordering v, |
| 16 |
_CmpUnspecifiedParam) noexcept { |
| 17 |
return v.value == 0; |
| 18 |
} |
| 19 |
friend constexpr bool operator<(strong_ordering v, |
| 20 |
_CmpUnspecifiedParam) noexcept { |
| 21 |
return v.value < 0; |
| 22 |
} |
| 23 |
friend constexpr bool operator>(strong_ordering v, |
| 24 |
_CmpUnspecifiedParam) noexcept { |
| 25 |
return v.value > 0; |
| 26 |
} |
| 27 |
friend constexpr bool operator>=(strong_ordering v, |
| 28 |
_CmpUnspecifiedParam) noexcept { |
| 29 |
return v.value >= 0; |
| 30 |
} |
| 31 |
static const strong_ordering equal, greater, less; |
| 32 |
}; |
| 33 |
constexpr strong_ordering strong_ordering::equal = {0}; |
| 34 |
constexpr strong_ordering strong_ordering::greater = {1}; |
| 35 |
constexpr strong_ordering strong_ordering::less = {-1}; |
| 36 |
} // namespace std |
| 37 |
|
| 38 |
struct A { |
| 39 |
int a; |
| 40 |
constexpr auto operator<=>(const A &other) const = default; |
| 41 |
}; |
| 42 |
|
| 43 |
void test_cxx_rewritten_binary_ops() { |
| 44 |
A a1, a2; |
| 45 |
bool result; |
| 46 |
result = (a1 < a2); |
| 47 |
result = (a1 >= a2); |
| 48 |
int *ptr = 0; // expected-warning{{zero as null pointer constant}} |
| 49 |
result = (a1 > (ptr == 0 ? a1 : a2)); // expected-warning{{zero as null pointer constant}} |
| 50 |
result = (a1 > ((a1 > (ptr == 0 ? a1 : a2)) ? a1 : a2)); // expected-warning{{zero as null pointer constant}} |
| 51 |
} |