summaryrefslogtreecommitdiffstats
path: root/clang/test
diff options
context:
space:
mode:
authorRichard Smith <richard-llvm@metafoo.co.uk>2017-12-01 02:13:10 +0000
committerRichard Smith <richard-llvm@metafoo.co.uk>2017-12-01 02:13:10 +0000
commitd30b23d6a54b3f0883914f3c2c2318a78edcbe67 (patch)
treec9958ae2b0ab602da82170f58caf6bd3ab898982 /clang/test
parent69989bdbf2538d64906d9a99e27f6f1e2ed3b190 (diff)
downloadbcm5719-llvm-d30b23d6a54b3f0883914f3c2c2318a78edcbe67.tar.gz
bcm5719-llvm-d30b23d6a54b3f0883914f3c2c2318a78edcbe67.zip
[c++2a] P0515R3: Support for overloaded operator<=>.
No CodeGen support for MSABI yet, we don't know how to mangle this there. llvm-svn: 319513
Diffstat (limited to 'clang/test')
-rw-r--r--clang/test/CodeGenCXX/cxx2a-three-way-comparison.cpp13
-rw-r--r--clang/test/Lexer/cxx2a-spaceship.cpp4
-rw-r--r--clang/test/SemaCXX/cxx2a-three-way-comparison.cpp24
3 files changed, 39 insertions, 2 deletions
diff --git a/clang/test/CodeGenCXX/cxx2a-three-way-comparison.cpp b/clang/test/CodeGenCXX/cxx2a-three-way-comparison.cpp
new file mode 100644
index 00000000000..08ab41b1eaa
--- /dev/null
+++ b/clang/test/CodeGenCXX/cxx2a-three-way-comparison.cpp
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -std=c++2a -emit-llvm %s -o - -triple %itanium_abi_triple | FileCheck %s --check-prefix=ITANIUM
+// RUN: not %clang_cc1 -std=c++2a -emit-llvm %s -o - -triple %ms_abi_triple 2>&1 | FileCheck %s --check-prefix=MSABI
+// MSABI: cannot mangle this three-way comparison operator yet
+
+struct A {
+ void operator<=>(int);
+};
+
+// ITANIUM: define {{.*}}@_ZN1AssEi(
+void A::operator<=>(int) {}
+
+// ITANIUM: define {{.*}}@_Zssi1A(
+void operator<=>(int, A) {}
diff --git a/clang/test/Lexer/cxx2a-spaceship.cpp b/clang/test/Lexer/cxx2a-spaceship.cpp
index f407937c4e3..604575ee976 100644
--- a/clang/test/Lexer/cxx2a-spaceship.cpp
+++ b/clang/test/Lexer/cxx2a-spaceship.cpp
@@ -10,7 +10,7 @@ namespace N {
struct A {};
void operator<=(A, A);
#if __cplusplus > 201703L
-void operator<=>(A, A); // expected-error {{}}
+void operator<=>(A, A);
#ifdef COMPAT
// expected-warning@-2 {{'<=>' operator is incompatible with C++ standards before C++2a}}
#endif
@@ -21,7 +21,7 @@ X<operator<=>
#if __cplusplus <= 201703L
// expected-warning@-2 {{'<=>' is a single token in C++2a; add a space to avoid a change in behavior}}
#else
- > // expected-error@-4 {{}}
+ >
#endif
#ifdef COMPAT
// expected-warning@-7 {{'<=>' operator is incompatible with C++ standards before C++2a}}
diff --git a/clang/test/SemaCXX/cxx2a-three-way-comparison.cpp b/clang/test/SemaCXX/cxx2a-three-way-comparison.cpp
new file mode 100644
index 00000000000..eb1480ce610
--- /dev/null
+++ b/clang/test/SemaCXX/cxx2a-three-way-comparison.cpp
@@ -0,0 +1,24 @@
+// RUN: %clang_cc1 -std=c++2a -verify %s
+
+struct A {};
+constexpr int operator<=>(A a, A b) { return 42; }
+static_assert(operator<=>(A(), A()) == 42);
+
+int operator<=>(); // expected-error {{overloaded 'operator<=>' must have at least one parameter of class or enumeration type}}
+int operator<=>(A); // expected-error {{overloaded 'operator<=>' must be a binary operator}}
+int operator<=>(int, int); // expected-error {{overloaded 'operator<=>' must have at least one parameter of class or enumeration type}}
+int operator<=>(A, A, A); // expected-error {{overloaded 'operator<=>' must be a binary operator}}
+int operator<=>(A, A, ...); // expected-error {{overloaded 'operator<=>' cannot be variadic}}
+int operator<=>(int, A = {}); // expected-error {{parameter of overloaded 'operator<=>' cannot have a default argument}}
+
+struct B {
+ int &operator<=>(int);
+ friend int operator<=>(A, B);
+
+ friend int operator<=>(int, int); // expected-error {{overloaded 'operator<=>' must have at least one parameter of class or enumeration type}}
+ void operator<=>(); // expected-error {{overloaded 'operator<=>' must be a binary operator}};
+ void operator<=>(A, ...); // expected-error {{overloaded 'operator<=>' cannot be variadic}}
+ void operator<=>(A, A); // expected-error {{overloaded 'operator<=>' must be a binary operator}};
+};
+
+int &r = B().operator<=>(0);
OpenPOWER on IntegriCloud