[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / SemaCXX / cxx2a-three-way-comparison.cpp
blobb94225274fffbb7a6ac0bc9d8dd0c90d2d412aaf
1 // RUN: %clang_cc1 -std=c++2a -verify %s -Wzero-as-null-pointer-constant
3 // Keep this test before any declarations of operator<=>.
4 namespace PR44786 {
5 template<typename T> void f(decltype(T{} <=> T{})) {} // expected-note {{previous}}
7 struct S {};
8 int operator<=>(S const &, S const &);
9 template<typename T> void f(decltype(T{} <=> T{})) {} // expected-error {{redefinition}}
12 struct A {};
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}}
23 struct B {
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);
35 namespace PR47893 {
36 struct A {
37 void operator<=>(const A&) const;
39 template<typename T> auto f(T a, T b) -> decltype(a < b) = delete;
40 int &f(...);
41 int &r = f(A(), A());
44 namespace PR44325 {
45 struct cmp_cat {};
46 bool operator<(cmp_cat, void*);
47 bool operator>(cmp_cat, int cmp_cat::*);
49 struct X {};
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}}