70 lines · cpp
1// RUN: %clang_cc1 -std=c++2a -verify %s -Wzero-as-null-pointer-constant2 3// Keep this test before any declarations of operator<=>.4namespace 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 12struct A {};13constexpr int operator<=>(A a, A b) { return 42; }14static_assert(operator<=>(A(), A()) == 42);15 16int operator<=>(); // expected-error {{overloaded 'operator<=>' must have at least one parameter of class or enumeration type}}17int operator<=>(A); // expected-error {{overloaded 'operator<=>' must be a binary operator}}18int operator<=>(int, int); // expected-error {{overloaded 'operator<=>' must have at least one parameter of class or enumeration type}}19int operator<=>(A, A, A); // expected-error {{overloaded 'operator<=>' must be a binary operator}}20int operator<=>(A, A, ...); // expected-error {{overloaded 'operator<=>' cannot be variadic}}21int operator<=>(int, A = {}); // expected-error {{parameter of overloaded 'operator<=>' cannot have a default argument}}22 23struct 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 33int &r = B().operator<=>(0);34 35namespace 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 44namespace 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 warning53 bool b2 = X() > X(); // no warning54 55 // FIXME: It's not clear whether warning here is useful, but we can't really56 // 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 the58 // implicit rewrite rules, not for explicit use by programs.59 bool c = cmp_cat() < 0; // expected-warning {{zero as null pointer constant}}60}61 62namespace GH137452 {63struct 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 GH13745270