[clang] 737f540 - [Sema][NFC] Add tests for builtin spaceship operator.
Clement Courbet via cfe-commits
cfe-commits at lists.llvm.org
Fri Nov 5 03:44:29 PDT 2021
Author: Clement Courbet
Date: 2021-11-05T11:44:19+01:00
New Revision: 737f540abd578df094f04f690a9b5b52028374b4
URL: https://github.com/llvm/llvm-project/commit/737f540abd578df094f04f690a9b5b52028374b4
DIFF: https://github.com/llvm/llvm-project/commit/737f540abd578df094f04f690a9b5b52028374b4.diff
LOG: [Sema][NFC] Add tests for builtin spaceship operator.
In preparation for D112453.
Added:
clang/test/CXX/over/over.built/ast-20.cpp
clang/test/CXX/over/over.built/spaceship.cpp
Modified:
Removed:
################################################################################
diff --git a/clang/test/CXX/over/over.built/ast-20.cpp b/clang/test/CXX/over/over.built/ast-20.cpp
new file mode 100644
index 0000000000000..4fd1c6edb34f6
--- /dev/null
+++ b/clang/test/CXX/over/over.built/ast-20.cpp
@@ -0,0 +1,22 @@
+// RUN: %clang_cc1 -std=c++20 -ast-dump %s -ast-dump-filter Test | FileCheck %s
+
+namespace std {
+ struct strong_ordering {
+ int n;
+ constexpr operator int() const { return n; }
+ static const strong_ordering less, equal, greater;
+ };
+ constexpr strong_ordering strong_ordering::less{-1},
+ strong_ordering::equal{0}, strong_ordering::greater{1};
+}
+
+template <typename T, typename U>
+auto Test(T* pt, U* pu) {
+ // CHECK: BinaryOperator {{.*}} '<dependent type>' '<=>'
+ // CHECK-NEXT: DeclRefExpr {{.*}} 'T *' lvalue ParmVar {{.*}} 'pt' 'T *'
+ // CHECK-NEXT: DeclRefExpr {{.*}} 'U *' lvalue ParmVar {{.*}} 'pu' 'U *'
+ (void)(pt <=> pu);
+
+}
+
+
diff --git a/clang/test/CXX/over/over.built/spaceship.cpp b/clang/test/CXX/over/over.built/spaceship.cpp
new file mode 100644
index 0000000000000..510d601578b5a
--- /dev/null
+++ b/clang/test/CXX/over/over.built/spaceship.cpp
@@ -0,0 +1,21 @@
+// RUN: %clang_cc1 -std=c++20 -verify %s -Wno-tautological-compare
+
+namespace std {
+ struct strong_ordering {
+ int n;
+ constexpr operator int() const { return n; }
+ static const strong_ordering less, equal, greater;
+ };
+ constexpr strong_ordering strong_ordering::less{-1},
+ strong_ordering::equal{0}, strong_ordering::greater{1};
+}
+
+template <typename T>
+void f(int i, int* pi, T* pt, T t) {
+ (void)(i <=> i);
+ (void)(i <=> pi); // expected-error {{comparison between pointer and integer}}
+ (void)(i <=> pt);
+ (void)(pi <=> pt);
+ (void)(pi <=> t);
+}
+
More information about the cfe-commits
mailing list