| 1 |
// RUN: %clang_cc1 -std=c++2a -verify %s -Wzero-as-null-pointer-constant |
| 2 |
|
| 3 |
// Keep this test before any declarations of operator<=>. |
| 4 |
namespace PR44786 { |
| 5 |
template<typename T> void f(decltype(T{} <=> T{})) {} // expected-note {{previous}} |
| 6 |
|
| 7 |
struct S {}; |
| 8 |
int operator<=>(S const &, S const &); |
| 9 |
template<typename T> void f(decltype(T{} <=> T{})) {} // expected-error {{redefinition}} |
| 10 |
} |
| 11 |
|
| 12 |
struct A {}; |
| 13 |
constexpr int operator<=>(A a, A b) { return 42; } |
| 14 |
static_assert(operator<=>(A(), A()) == 42); |
| 15 |
|
| 16 |
int operator<=>(); // expected-error {{overloaded 'operator<=>' must have at least one parameter of class or enumeration type}} |
| 17 |
int operator<=>(A); // expected-error {{overloaded 'operator<=>' must be a binary operator}} |
| 18 |
int operator<=>(int, int); // expected-error {{overloaded 'operator<=>' must have at least one parameter of class or enumeration type}} |
| 19 |
int operator<=>(A, A, A); // expected-error {{overloaded 'operator<=>' must be a binary operator}} |
| 20 |
int operator<=>(A, A, ...); // expected-error {{overloaded 'operator<=>' cannot be variadic}} |
| 21 |
int operator<=>(int, A = {}); // expected-error {{parameter of overloaded 'operator<=>' cannot have a default argument}} |
| 22 |
|
| 23 |
struct B { |
| 24 |
int &operator<=>(int); |
| 25 |
friend int operator<=>(A, B); |
| 26 |
|
| 27 |
friend int operator<=>(int, int); // expected-error {{overloaded 'operator<=>' must have at least one parameter of class or enumeration type}} |
| 28 |
void operator<=>(); // expected-error {{overloaded 'operator<=>' must be a binary operator}}; |
| 29 |
void operator<=>(A, ...); // expected-error {{overloaded 'operator<=>' cannot be variadic}} |
| 30 |
void operator<=>(A, A); // expected-error {{overloaded 'operator<=>' must be a binary operator}}; |
| 31 |
}; |
| 32 |
|
| 33 |
int &r = B().operator<=>(0); |
| 34 |
|
| 35 |
namespace PR47893 { |
| 36 |
struct A { |
| 37 |
void operator<=>(const A&) const; |
| 38 |
}; |
| 39 |
template<typename T> auto f(T a, T b) -> decltype(a < b) = delete; |
| 40 |
int &f(...); |
| 41 |
int &r = f(A(), A()); |
| 42 |
} |
| 43 |
|
| 44 |
namespace PR44325 { |
| 45 |
struct cmp_cat {}; |
| 46 |
bool operator<(cmp_cat, void*); |
| 47 |
bool operator>(cmp_cat, int cmp_cat::*); |
| 48 |
|
| 49 |
struct X {}; |
| 50 |
cmp_cat operator<=>(X, X); |
| 51 |
|
| 52 |
bool b1 = X() < X(); // no warning |
| 53 |
bool b2 = X() > X(); // no warning |
| 54 |
|
| 55 |
// FIXME: It's not clear whether warning here is useful, but we can't really |
| 56 |
// tell that this is a comparison category in general. This is probably OK, |
| 57 |
// as comparisons against zero are only really intended for use in the |
| 58 |
// implicit rewrite rules, not for explicit use by programs. |
| 59 |
bool c = cmp_cat() < 0; // expected-warning {{zero as null pointer constant}} |
| 60 |
} |
| 61 |
|
| 62 |
namespace GH137452 { |
| 63 |
struct comparable_t { |
| 64 |
__attribute__((vector_size(32))) double numbers; // expected-note {{declared here}} |
| 65 |
auto operator<=>(const comparable_t& rhs) const = default; // expected-warning {{explicitly defaulted three-way comparison operator is implicitly deleted}} \ |
| 66 |
expected-note {{replace 'default' with 'delete'}} \ |
| 67 |
expected-note {{defaulted 'operator<=>' is implicitly deleted because defaulted comparison of vector types is not supported}} |
| 68 |
}; |
| 69 |
} // namespace GH137452 |