1 // RUN: %clang_cc1 -std=c++2a -verify %s
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 {};
operator <=>(A a,A b)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