1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 // UNSUPPORTED: c++03, c++11, c++14, c++17
10 // UNSUPPORTED: libcpp-no-concepts
11 
12 // <utility>
13 
14 // template<class T, class U>
15 //   constexpr bool cmp_equal(T t, U u) noexcept; // C++20
16 
17 // template<class T, class U>
18 //   constexpr bool cmp_not_equal(T t, U u) noexcept; // C++20
19 
20 // template<class T, class U>
21 //   constexpr bool cmp_less(T t, U u) noexcept; // C++20
22 
23 // template<class T, class U>
24 //   constexpr bool cmp_less_equal(T t, U u) noexcept; // C++20
25 
26 // template<class T, class U>
27 //   constexpr bool cmp_greater(T t, U u) noexcept; // C++20
28 
29 // template<class T, class U>
30 //   constexpr bool cmp_greater_equal(T t, U u) noexcept; // C++20
31 
32 // template<class R, class T>
33 //   constexpr bool in_range(T t) noexcept;      // C++20
34 
35 #include <utility>
36 
37 #include "test_macros.h"
38 
39 struct NonEmptyT {
40   int val;
41   NonEmptyT() : val(0) {}
42   NonEmptyT(int val) : val(val) {}
43   operator int&() { return val; }
44   operator int() const { return val; }
45 };
46 
47 enum ColorT { red, green, blue };
48 
49 struct EmptyT {};
50 
51 template <class T>
52 constexpr void test() {
53   std::cmp_equal(T(), T()); // expected-error11{{no matching function for call to 'cmp_equal'}}
54   std::cmp_equal(T(), int()); // expected-error11{{no matching function for call to 'cmp_equal'}}
55   std::cmp_equal(int(), T()); // expected-error11{{no matching function for call to 'cmp_equal'}}
56   std::cmp_not_equal(T(), T()); // expected-error11{{no matching function for call to 'cmp_not_equal'}}
57   std::cmp_not_equal(T(), int()); // expected-error11{{no matching function for call to 'cmp_not_equal'}}
58   std::cmp_not_equal(int(), T()); // expected-error11{{no matching function for call to 'cmp_not_equal'}}
59   std::cmp_less(T(), T()); // expected-error11{{no matching function for call to 'cmp_less'}}
60   std::cmp_less(T(), int()); // expected-error11{{no matching function for call to 'cmp_less'}}
61   std::cmp_less(int(), T()); // expected-error11{{no matching function for call to 'cmp_less'}}
62   std::cmp_less_equal(T(), T()); // expected-error11{{no matching function for call to 'cmp_less_equal'}}
63   std::cmp_less_equal(T(), int()); // expected-error11{{no matching function for call to 'cmp_less_equal'}}
64   std::cmp_less_equal(int(), T()); // expected-error11{{no matching function for call to 'cmp_less_equal'}}
65   std::cmp_greater(T(), T()); // expected-error11{{no matching function for call to 'cmp_greater'}}
66   std::cmp_greater(T(), int()); // expected-error11{{no matching function for call to 'cmp_greater'}}
67   std::cmp_greater(int(), T()); // expected-error11{{no matching function for call to 'cmp_greater'}}
68   std::cmp_greater_equal(T(), T()); // expected-error11{{no matching function for call to 'cmp_greater_equal'}}
69   std::cmp_greater_equal(T(), int()); // expected-error11{{no matching function for call to 'cmp_greater_equal'}}
70   std::cmp_greater_equal(int(), T()); // expected-error11{{no matching function for call to 'cmp_greater_equal'}}
71   std::in_range<T>(int()); // expected-error11{{no matching function for call to 'in_range'}}
72   std::in_range<int>(T()); // expected-error11{{no matching function for call to 'in_range'}}
73 }
74 #ifndef _LIBCPP_HAS_NO_CHAR8_T
75 template <class T>
76 constexpr void test_char8t() {
77   std::cmp_equal(T(), T()); // expected-error1{{no matching function for call to 'cmp_equal'}}
78   std::cmp_equal(T(), int()); // expected-error1{{no matching function for call to 'cmp_equal'}}
79   std::cmp_equal(int(), T()); // expected-error1{{no matching function for call to 'cmp_equal'}}
80   std::cmp_not_equal(T(), T()); // expected-error1{{no matching function for call to 'cmp_not_equal'}}
81   std::cmp_not_equal(T(), int()); // expected-error1{{no matching function for call to 'cmp_not_equal'}}
82   std::cmp_not_equal(int(), T()); // expected-error1{{no matching function for call to 'cmp_not_equal'}}
83   std::cmp_less(T(), T()); // expected-error1{{no matching function for call to 'cmp_less'}}
84   std::cmp_less(T(), int()); // expected-error1{{no matching function for call to 'cmp_less'}}
85   std::cmp_less(int(), T()); // expected-error1{{no matching function for call to 'cmp_less'}}
86   std::cmp_less_equal(T(), T()); // expected-error1{{no matching function for call to 'cmp_less_equal'}}
87   std::cmp_less_equal(T(), int()); // expected-error1{{no matching function for call to 'cmp_less_equal'}}
88   std::cmp_less_equal(int(), T()); // expected-error1{{no matching function for call to 'cmp_less_equal'}}
89   std::cmp_greater(T(), T()); // expected-error1{{no matching function for call to 'cmp_greater'}}
90   std::cmp_greater(T(), int()); // expected-error1{{no matching function for call to 'cmp_greater'}}
91   std::cmp_greater(int(), T()); // expected-error1{{no matching function for call to 'cmp_greater'}}
92   std::cmp_greater_equal(T(), T()); // expected-error1{{no matching function for call to 'cmp_greater_equal'}}
93   std::cmp_greater_equal(T(), int()); // expected-error1{{no matching function for call to 'cmp_greater_equal'}}
94   std::cmp_greater_equal(int(), T()); // expected-error1{{no matching function for call to 'cmp_greater_equal'}}
95   std::in_range<T>(int()); // expected-error1{{no matching function for call to 'in_range'}}
96   std::in_range<int>(T()); // expected-error1{{no matching function for call to 'in_range'}}
97 }
98 #endif // _LIBCPP_HAS_NO_CHAR8_T
99 
100 #ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
101 template <class T>
102 constexpr void test_uchars() {
103   std::cmp_equal(T(), T()); // expected-error2{{no matching function for call to 'cmp_equal'}}
104   std::cmp_equal(T(), int()); // expected-error2{{no matching function for call to 'cmp_equal'}}
105   std::cmp_equal(int(), T()); // expected-error2{{no matching function for call to 'cmp_equal'}}
106   std::cmp_not_equal(T(), T()); // expected-error2{{no matching function for call to 'cmp_not_equal'}}
107   std::cmp_not_equal(T(), int()); // expected-error2{{no matching function for call to 'cmp_not_equal'}}
108   std::cmp_not_equal(int(), T()); // expected-error2{{no matching function for call to 'cmp_not_equal'}}
109   std::cmp_less(T(), T()); // expected-error2{{no matching function for call to 'cmp_less'}}
110   std::cmp_less(T(), int()); // expected-error2{{no matching function for call to 'cmp_less'}}
111   std::cmp_less(int(), T()); // expected-error2{{no matching function for call to 'cmp_less'}}
112   std::cmp_less_equal(T(), T()); // expected-error2{{no matching function for call to 'cmp_less_equal'}}
113   std::cmp_less_equal(T(), int()); // expected-error2{{no matching function for call to 'cmp_less_equal'}}
114   std::cmp_less_equal(int(), T()); // expected-error2{{no matching function for call to 'cmp_less_equal'}}
115   std::cmp_greater(T(), T()); // expected-error2{{no matching function for call to 'cmp_greater'}}
116   std::cmp_greater(T(), int()); // expected-error2{{no matching function for call to 'cmp_greater'}}
117   std::cmp_greater(int(), T()); // expected-error2{{no matching function for call to 'cmp_greater'}}
118   std::cmp_greater_equal(T(), T()); // expected-error2{{no matching function for call to 'cmp_greater_equal'}}
119   std::cmp_greater_equal(T(), int()); // expected-error2{{no matching function for call to 'cmp_greater_equal'}}
120   std::cmp_greater_equal(int(), T()); // expected-error2{{no matching function for call to 'cmp_greater_equal'}}
121   std::in_range<T>(int()); // expected-error2{{no matching function for call to 'in_range'}}
122   std::in_range<int>(T()); // expected-error2{{no matching function for call to 'in_range'}}
123 }
124 #endif // _LIBCPP_HAS_NO_UNICODE_CHARS
125 
126 int main() {
127   test<bool>();
128   test<char>();
129   test<wchar_t>();
130   test<float>();
131   test<double>();
132   test<long double>();
133   test<std::byte>();
134   test<NonEmptyT>();
135   test<ColorT>();
136   test<nullptr_t>();
137   test<EmptyT>();
138 
139 #ifndef _LIBCPP_HAS_NO_CHAR8_T
140   test_char8t<char8_t>();
141 #endif // _LIBCPP_HAS_NO_CHAR8_T
142 
143 #ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
144   test_uchars<char16_t>();
145   test_uchars<char32_t>();
146 #endif // _LIBCPP_HAS_NO_UNICODE_CHARS
147 
148   return 0;
149 }
150