Skip to content

Commit

Permalink
[Sema][NFC] Add tests for builtin spaceship operator.
Browse files Browse the repository at this point in the history
In preparation for D112453.
  • Loading branch information
legrosbuffle committed Nov 5, 2021
1 parent 44596fe commit 737f540
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
22 changes: 22 additions & 0 deletions clang/test/CXX/over/over.built/ast-20.cpp
Original file line number Diff line number Diff line change
@@ -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);

}


21 changes: 21 additions & 0 deletions clang/test/CXX/over/over.built/spaceship.cpp
Original file line number Diff line number Diff line change
@@ -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);
}

0 comments on commit 737f540

Please sign in to comment.