1 // RUN: %clang_cc1 -std=c++2a -verify %s -Wzero-as-null-pointer-constant
3 // Keep this test before any declarations of operator<=>.
5 template<typename T
> void f(decltype(T
{} <=> T
{})) {} // expected-note {{previous}}
8 int operator<=>(S
const &, S
const &);
9 template<typename T
> void f(decltype(T
{} <=> T
{})) {} // expected-error {{redefinition}}
13 constexpr int operator<=>(A a
, A b
) { return 42; }
14 static_assert(operator<=>(A(), A()) == 42);
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}}
24 int &operator<=>(int);
25 friend int operator<=>(A
, B
);
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}};
33 int &r
= B().operator<=>(0);
37 void operator<=>(const A
&) const;
39 template<typename T
> auto f(T a
, T b
) -> decltype(a
< b
) = delete;
46 bool operator<(cmp_cat
, void*);
47 bool operator>(cmp_cat
, int cmp_cat::*);
50 cmp_cat
operator<=>(X
, X
);
52 bool b1
= X() < X(); // no warning
53 bool b2
= X() > X(); // no warning
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}}