[RISCV] Fix mgather -> riscv.masked.strided.load combine not extending indices (...
[llvm-project.git] / libcxx / test / std / algorithms / robust_against_adl.compile.pass.cpp
blob6e6cddfcee2bbf5aa2cfe98bfcddae10c6dd7a41
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 //===----------------------------------------------------------------------===//
9 // <algorithm>
11 // https://buildkite.com/llvm-project/libcxx-ci/builds/15823#0184fc0b-d56b-4774-9e1d-35fe24e09e37
12 // It seems like the CI gcc version is buggy. I can't reproduce the failure on my system or on
13 // godbolt (https://godbolt.org/z/rsPv8e8fn).
14 // UNSUPPORTED: gcc-13
16 #include <algorithm>
17 #include <cstddef>
18 #include <functional>
19 #include <iterator>
21 #include "test_macros.h"
23 struct Incomplete;
24 template<class T> struct Holder { T t; };
26 template<class>
27 struct ConvertibleToIntegral {
28 TEST_CONSTEXPR operator int() const { return 1; }
31 struct Tester {
32 using Element = Holder<Incomplete>*;
33 Element data[10] = {};
36 struct UnaryVoid { TEST_CONSTEXPR_CXX14 void operator()(void*) const {} };
37 struct UnaryTrue { TEST_CONSTEXPR bool operator()(void*) const { return true; } };
38 struct NullaryValue { TEST_CONSTEXPR std::nullptr_t operator()() const { return nullptr; } };
39 struct UnaryTransform { TEST_CONSTEXPR std::nullptr_t operator()(void*) const { return nullptr; } };
40 struct BinaryTransform { TEST_CONSTEXPR std::nullptr_t operator()(void*, void*) const { return nullptr; } };
42 TEST_CONSTEXPR_CXX20 bool all_the_algorithms()
44 Tester t;
45 Tester u;
46 Holder<Incomplete> **first = t.data;
47 Holder<Incomplete> **mid = t.data+5;
48 Holder<Incomplete> **last = t.data+10;
49 Holder<Incomplete> **first2 = u.data;
50 Holder<Incomplete> **mid2 = u.data+5;
51 Holder<Incomplete> **last2 = u.data+10;
52 Tester::Element value = nullptr;
53 ConvertibleToIntegral<Tester::Element> count;
55 (void)std::adjacent_find(first, last);
56 (void)std::adjacent_find(first, last, std::equal_to<void*>());
57 #if TEST_STD_VER >= 11
58 (void)std::all_of(first, last, UnaryTrue());
59 (void)std::any_of(first, last, UnaryTrue());
60 #endif
61 (void)std::binary_search(first, last, value);
62 (void)std::binary_search(first, last, value, std::less<void*>());
63 #if TEST_STD_VER > 17
64 (void)std::clamp(value, value, value);
65 (void)std::clamp(value, value, value, std::less<void*>());
66 #endif
67 (void)std::copy(first, last, first2);
68 (void)std::copy_backward(first, last, last2);
69 (void)std::copy_n(first, count, first2);
70 (void)std::count(first, last, value);
71 (void)std::count_if(first, last, UnaryTrue());
72 (void)std::distance(first, last);
73 (void)std::equal(first, last, first2);
74 (void)std::equal(first, last, first2, std::equal_to<void*>());
75 #if TEST_STD_VER > 11
76 (void)std::equal(first, last, first2, last2);
77 (void)std::equal(first, last, first2, last2, std::equal_to<void*>());
78 #endif
79 (void)std::equal_range(first, last, value);
80 (void)std::equal_range(first, last, value, std::less<void*>());
81 (void)std::fill(first, last, value);
82 (void)std::fill_n(first, count, value);
83 (void)std::find(first, last, value);
84 (void)std::find_end(first, last, first2, mid2);
85 (void)std::find_end(first, last, first2, mid2, std::equal_to<void*>());
86 (void)std::find_if(first, last, UnaryTrue());
87 (void)std::find_if_not(first, last, UnaryTrue());
88 (void)std::for_each(first, last, UnaryVoid());
89 #if TEST_STD_VER > 14
90 (void)std::for_each_n(first, count, UnaryVoid());
91 #endif
92 (void)std::generate(first, last, NullaryValue());
93 (void)std::generate_n(first, count, NullaryValue());
94 (void)std::includes(first, last, first2, last2);
95 (void)std::includes(first, last, first2, last2, std::less<void*>());
96 (void)std::is_heap(first, last);
97 (void)std::is_heap(first, last, std::less<void*>());
98 (void)std::is_heap_until(first, last);
99 (void)std::is_heap_until(first, last, std::less<void*>());
100 (void)std::is_partitioned(first, last, UnaryTrue());
101 (void)std::is_permutation(first, last, first2);
102 (void)std::is_permutation(first, last, first2, std::equal_to<void*>());
103 #if TEST_STD_VER > 11
104 (void)std::is_permutation(first, last, first2, last2);
105 (void)std::is_permutation(first, last, first2, last2, std::equal_to<void*>());
106 #endif
107 (void)std::is_sorted(first, last);
108 (void)std::is_sorted(first, last, std::less<void*>());
109 (void)std::is_sorted_until(first, last);
110 (void)std::is_sorted_until(first, last, std::less<void*>());
111 // RELIES ON ADL SWAP (void)std::inplace_merge(first, mid, last);
112 // RELIES ON ADL SWAP (void)std::inplace_merge(first, mid, last, std::less<void*>());
113 // RELIES ON ADL SWAP (void)std::iter_swap(first, mid);
114 (void)std::lexicographical_compare(first, last, first2, last2);
115 (void)std::lexicographical_compare(first, last, first2, last2, std::less<void*>());
116 #if TEST_STD_VER > 17
117 (void)std::lexicographical_compare_three_way(first, last, first2, last2);
118 (void)std::lexicographical_compare_three_way(first, last, first2, last2, std::compare_three_way());
119 #endif
120 (void)std::lower_bound(first, last, value);
121 (void)std::lower_bound(first, last, value, std::less<void*>());
122 (void)std::make_heap(first, last);
123 (void)std::make_heap(first, last, std::less<void*>());
124 (void)std::max(value, value);
125 (void)std::max(value, value, std::less<void*>());
126 #if TEST_STD_VER >= 11
127 (void)std::max({ value, value });
128 (void)std::max({ value, value }, std::less<void*>());
129 #endif
130 (void)std::max_element(first, last);
131 (void)std::max_element(first, last, std::less<void*>());
132 (void)std::merge(first, mid, mid, last, first2);
133 (void)std::merge(first, mid, mid, last, first2, std::less<void*>());
134 (void)std::min(value, value);
135 (void)std::min(value, value, std::less<void*>());
136 #if TEST_STD_VER >= 11
137 (void)std::min({ value, value });
138 (void)std::min({ value, value }, std::less<void*>());
139 #endif
140 (void)std::min_element(first, last);
141 (void)std::min_element(first, last, std::less<void*>());
142 (void)std::minmax(value, value);
143 (void)std::minmax(value, value, std::less<void*>());
144 #if TEST_STD_VER >= 11
145 (void)std::minmax({ value, value });
146 (void)std::minmax({ value, value }, std::less<void*>());
147 #endif
148 (void)std::minmax_element(first, last);
149 (void)std::minmax_element(first, last, std::less<void*>());
150 (void)std::mismatch(first, last, first2);
151 (void)std::mismatch(first, last, first2, std::equal_to<void*>());
152 #if TEST_STD_VER > 11
153 (void)std::mismatch(first, last, first2, last2);
154 (void)std::mismatch(first, last, first2, last2, std::equal_to<void*>());
155 #endif
156 (void)std::move(first, last, first2);
157 (void)std::move_backward(first, last, last2);
158 // RELIES ON ADL SWAP (void)std::next_permutation(first, last);
159 // RELIES ON ADL SWAP (void)std::next_permutation(first, last, std::less<void*>());
160 #if TEST_STD_VER >= 11
161 (void)std::none_of(first, last, UnaryTrue());
162 #endif
163 // RELIES ON ADL SWAP (void)std::nth_element(first, mid, last);
164 // RELIES ON ADL SWAP (void)std::nth_element(first, mid, last, std::less<void*>());
165 // RELIES ON ADL SWAP (void)std::partial_sort(first, mid, last);
166 // RELIES ON ADL SWAP (void)std::partial_sort(first, mid, last, std::less<void*>());
167 (void)std::partial_sort_copy(first, last, first2, mid2);
168 (void)std::partial_sort_copy(first, last, first2, mid2, std::less<void*>());
169 // RELIES ON ADL SWAP (void)std::partition(first, last, UnaryTrue());
170 (void)std::partition_copy(first, last, first2, last2, UnaryTrue());
171 (void)std::partition_point(first, last, UnaryTrue());
172 (void)std::pop_heap(first, last);
173 (void)std::pop_heap(first, last, std::less<void*>());
174 // RELIES ON ADL SWAP (void)std::prev_permutation(first, last);
175 // RELIES ON ADL SWAP (void)std::prev_permutation(first, last, std::less<void*>());
176 (void)std::push_heap(first, last);
177 (void)std::push_heap(first, last, std::less<void*>());
178 (void)std::remove(first, last, value);
179 (void)std::remove_copy(first, last, first2, value);
180 (void)std::remove_copy_if(first, last, first2, UnaryTrue());
181 (void)std::remove_if(first, last, UnaryTrue());
182 (void)std::replace(first, last, value, value);
183 (void)std::replace_copy(first, last, first2, value, value);
184 (void)std::replace_copy_if(first, last, first2, UnaryTrue(), value);
185 (void)std::replace_if(first, last, UnaryTrue(), value);
186 // RELIES ON ADL SWAP (void)std::reverse(first, last);
187 (void)std::reverse_copy(first, last, first2);
188 // RELIES ON ADL SWAP (void)std::rotate(first, mid, last);
189 (void)std::rotate_copy(first, mid, last, first2);
190 (void)std::search(first, last, first2, mid2);
191 (void)std::search(first, last, first2, mid2, std::equal_to<void*>());
192 (void)std::search_n(first, last, count, value);
193 (void)std::search_n(first, last, count, value, std::equal_to<void*>());
194 (void)std::set_difference(first, mid, mid, last, first2);
195 (void)std::set_difference(first, mid, mid, last, first2, std::less<void*>());
196 (void)std::set_intersection(first, mid, mid, last, first2);
197 (void)std::set_intersection(first, mid, mid, last, first2, std::less<void*>());
198 (void)std::set_symmetric_difference(first, mid, mid, last, first2);
199 (void)std::set_symmetric_difference(first, mid, mid, last, first2, std::less<void*>());
200 (void)std::set_union(first, mid, mid, last, first2);
201 (void)std::set_union(first, mid, mid, last, first2, std::less<void*>());
202 #if TEST_STD_VER > 17
203 (void)std::shift_left(first, last, count);
204 (void)std::shift_right(first, last, count);
205 #endif
206 // RELIES ON ADL SWAP (void)std::sort(first, last);
207 // RELIES ON ADL SWAP (void)std::sort(first, last, std::less<void*>());
208 (void)std::sort_heap(first, last);
209 (void)std::sort_heap(first, last, std::less<void*>());
210 // RELIES ON ADL SWAP (void)std::stable_partition(first, last, UnaryTrue());
211 // RELIES ON ADL SWAP (void)std::stable_sort(first, last);
212 // RELIES ON ADL SWAP (void)std::stable_sort(first, last, std::less<void*>());
213 // RELIES ON ADL SWAP (void)std::swap_ranges(first, last, first2);
214 (void)std::transform(first, last, first2, UnaryTransform());
215 (void)std::transform(first, mid, mid, first2, BinaryTransform());
216 (void)std::unique(first, last);
217 (void)std::unique(first, last, std::equal_to<void*>());
218 (void)std::unique_copy(first, last, first2);
219 (void)std::unique_copy(first, last, first2, std::equal_to<void*>());
220 (void)std::upper_bound(first, last, value);
221 (void)std::upper_bound(first, last, value, std::less<void*>());
223 return true;
226 void test()
228 all_the_algorithms();
229 #if TEST_STD_VER > 17
230 static_assert(all_the_algorithms());
231 #endif