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 #include <cstddef>
37 
38 #include "test_macros.h"
39 
40 struct NonEmptyT {
41   int val;
42   NonEmptyT() : val(0) {}
43   NonEmptyT(int val) : val(val) {}
44   operator int&() { return val; }
45   operator int() const { return val; }
46 };
47 
48 enum ColorT { red, green, blue };
49 
50 struct EmptyT {};
51 
52 template <class T>
53 constexpr void test() {
54   std::cmp_equal(T(), T()); // expected-error 10-11 {{no matching function for call to 'cmp_equal'}}
55   std::cmp_equal(T(), int()); // expected-error 10-11 {{no matching function for call to 'cmp_equal'}}
56   std::cmp_equal(int(), T()); // expected-error 10-11 {{no matching function for call to 'cmp_equal'}}
57   std::cmp_not_equal(T(), T()); // expected-error 10-11 {{no matching function for call to 'cmp_not_equal'}}
58   std::cmp_not_equal(T(), int()); // expected-error 10-11 {{no matching function for call to 'cmp_not_equal'}}
59   std::cmp_not_equal(int(), T()); // expected-error 10-11 {{no matching function for call to 'cmp_not_equal'}}
60   std::cmp_less(T(), T()); // expected-error 10-11 {{no matching function for call to 'cmp_less'}}
61   std::cmp_less(T(), int()); // expected-error 10-11 {{no matching function for call to 'cmp_less'}}
62   std::cmp_less(int(), T()); // expected-error 10-11 {{no matching function for call to 'cmp_less'}}
63   std::cmp_less_equal(T(), T()); // expected-error 10-11 {{no matching function for call to 'cmp_less_equal'}}
64   std::cmp_less_equal(T(), int()); // expected-error 10-11 {{no matching function for call to 'cmp_less_equal'}}
65   std::cmp_less_equal(int(), T()); // expected-error 10-11 {{no matching function for call to 'cmp_less_equal'}}
66   std::cmp_greater(T(), T()); // expected-error 10-11 {{no matching function for call to 'cmp_greater'}}
67   std::cmp_greater(T(), int()); // expected-error 10-11 {{no matching function for call to 'cmp_greater'}}
68   std::cmp_greater(int(), T()); // expected-error 10-11 {{no matching function for call to 'cmp_greater'}}
69   std::cmp_greater_equal(T(), T()); // expected-error 10-11 {{no matching function for call to 'cmp_greater_equal'}}
70   std::cmp_greater_equal(T(), int()); // expected-error 10-11 {{no matching function for call to 'cmp_greater_equal'}}
71   std::cmp_greater_equal(int(), T()); // expected-error 10-11 {{no matching function for call to 'cmp_greater_equal'}}
72   std::in_range<T>(int()); // expected-error 10-11 {{no matching function for call to 'in_range'}}
73   std::in_range<int>(T()); // expected-error 10-11 {{no matching function for call to 'in_range'}}
74 }
75 #ifndef _LIBCPP_HAS_NO_CHAR8_T
76 template <class T>
77 constexpr void test_char8t() {
78   std::cmp_equal(T(), T()); // expected-error 1 {{no matching function for call to 'cmp_equal'}}
79   std::cmp_equal(T(), int()); // expected-error 1 {{no matching function for call to 'cmp_equal'}}
80   std::cmp_equal(int(), T()); // expected-error 1 {{no matching function for call to 'cmp_equal'}}
81   std::cmp_not_equal(T(), T()); // expected-error 1 {{no matching function for call to 'cmp_not_equal'}}
82   std::cmp_not_equal(T(), int()); // expected-error 1 {{no matching function for call to 'cmp_not_equal'}}
83   std::cmp_not_equal(int(), T()); // expected-error 1 {{no matching function for call to 'cmp_not_equal'}}
84   std::cmp_less(T(), T()); // expected-error 1 {{no matching function for call to 'cmp_less'}}
85   std::cmp_less(T(), int()); // expected-error 1 {{no matching function for call to 'cmp_less'}}
86   std::cmp_less(int(), T()); // expected-error 1 {{no matching function for call to 'cmp_less'}}
87   std::cmp_less_equal(T(), T()); // expected-error 1 {{no matching function for call to 'cmp_less_equal'}}
88   std::cmp_less_equal(T(), int()); // expected-error 1 {{no matching function for call to 'cmp_less_equal'}}
89   std::cmp_less_equal(int(), T()); // expected-error 1 {{no matching function for call to 'cmp_less_equal'}}
90   std::cmp_greater(T(), T()); // expected-error 1 {{no matching function for call to 'cmp_greater'}}
91   std::cmp_greater(T(), int()); // expected-error 1 {{no matching function for call to 'cmp_greater'}}
92   std::cmp_greater(int(), T()); // expected-error 1 {{no matching function for call to 'cmp_greater'}}
93   std::cmp_greater_equal(T(), T()); // expected-error 1 {{no matching function for call to 'cmp_greater_equal'}}
94   std::cmp_greater_equal(T(), int()); // expected-error 1 {{no matching function for call to 'cmp_greater_equal'}}
95   std::cmp_greater_equal(int(), T()); // expected-error 1 {{no matching function for call to 'cmp_greater_equal'}}
96   std::in_range<T>(int()); // expected-error 1 {{no matching function for call to 'in_range'}}
97   std::in_range<int>(T()); // expected-error 1 {{no matching function for call to 'in_range'}}
98 }
99 #endif // _LIBCPP_HAS_NO_CHAR8_T
100 
101 #ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
102 template <class T>
103 constexpr void test_uchars() {
104   std::cmp_equal(T(), T()); // expected-error 2 {{no matching function for call to 'cmp_equal'}}
105   std::cmp_equal(T(), int()); // expected-error 2 {{no matching function for call to 'cmp_equal'}}
106   std::cmp_equal(int(), T()); // expected-error 2 {{no matching function for call to 'cmp_equal'}}
107   std::cmp_not_equal(T(), T()); // expected-error 2 {{no matching function for call to 'cmp_not_equal'}}
108   std::cmp_not_equal(T(), int()); // expected-error 2 {{no matching function for call to 'cmp_not_equal'}}
109   std::cmp_not_equal(int(), T()); // expected-error 2 {{no matching function for call to 'cmp_not_equal'}}
110   std::cmp_less(T(), T()); // expected-error 2 {{no matching function for call to 'cmp_less'}}
111   std::cmp_less(T(), int()); // expected-error 2 {{no matching function for call to 'cmp_less'}}
112   std::cmp_less(int(), T()); // expected-error 2 {{no matching function for call to 'cmp_less'}}
113   std::cmp_less_equal(T(), T()); // expected-error 2 {{no matching function for call to 'cmp_less_equal'}}
114   std::cmp_less_equal(T(), int()); // expected-error 2 {{no matching function for call to 'cmp_less_equal'}}
115   std::cmp_less_equal(int(), T()); // expected-error 2 {{no matching function for call to 'cmp_less_equal'}}
116   std::cmp_greater(T(), T()); // expected-error 2 {{no matching function for call to 'cmp_greater'}}
117   std::cmp_greater(T(), int()); // expected-error 2 {{no matching function for call to 'cmp_greater'}}
118   std::cmp_greater(int(), T()); // expected-error 2 {{no matching function for call to 'cmp_greater'}}
119   std::cmp_greater_equal(T(), T()); // expected-error 2 {{no matching function for call to 'cmp_greater_equal'}}
120   std::cmp_greater_equal(T(), int()); // expected-error 2 {{no matching function for call to 'cmp_greater_equal'}}
121   std::cmp_greater_equal(int(), T()); // expected-error 2 {{no matching function for call to 'cmp_greater_equal'}}
122   std::in_range<T>(int()); // expected-error 2 {{no matching function for call to 'in_range'}}
123   std::in_range<int>(T()); // expected-error 2 {{no matching function for call to 'in_range'}}
124 }
125 #endif // _LIBCPP_HAS_NO_UNICODE_CHARS
126 
127 int main(int, char**) {
128   test<bool>();
129   test<char>();
130 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
131   test<wchar_t>();
132 #endif
133   test<float>();
134   test<double>();
135   test<long double>();
136   test<std::byte>();
137   test<NonEmptyT>();
138   test<ColorT>();
139   test<std::nullptr_t>();
140   test<EmptyT>();
141 
142 #ifndef _LIBCPP_HAS_NO_CHAR8_T
143   test_char8t<char8_t>();
144 #endif // _LIBCPP_HAS_NO_CHAR8_T
145 
146 #ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
147   test_uchars<char16_t>();
148   test_uchars<char32_t>();
149 #endif
150 
151   return 0;
152 }
153