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// <algorithm>
10
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
15
16#include <algorithm>
17#include <cstddef>
18#include <functional>
19#include <iterator>
20
21#include "test_macros.h"
22
23struct Incomplete;
24template<class T> struct Holder { T t; };
25
26template<class>
27struct ConvertibleToIntegral {
28 TEST_CONSTEXPR operator int() const { return 1; }
29};
30
31struct Tester {
32 using Element = Holder<Incomplete>*;
33 Element data[10] = {};
34};
35
36struct UnaryVoid { TEST_CONSTEXPR_CXX14 void operator()(void*) const {} };
37struct UnaryTrue { TEST_CONSTEXPR bool operator()(void*) const { return true; } };
38struct NullaryValue { TEST_CONSTEXPR std::nullptr_t operator()() const { return nullptr; } };
39struct UnaryTransform { TEST_CONSTEXPR std::nullptr_t operator()(void*) const { return nullptr; } };
40struct BinaryTransform { TEST_CONSTEXPR std::nullptr_t operator()(void*, void*) const { return nullptr; } };
41
42TEST_CONSTEXPR_CXX20 bool all_the_algorithms()
43{
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;
54
55 (void)std::adjacent_find(first: first, last: last);
56 (void)std::adjacent_find(first: first, last: last, binary_pred: 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: first, last: last, val: value);
62 (void)std::binary_search(first: first, last: last, val: value, comp: 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: first, last: last, result: first2);
68 (void)std::copy_backward(first: first, last: last, result: last2);
69 (void)std::copy_n(first: first, n: count, result: first2);
70 (void)std::count(first: first, last: last, value: value);
71 (void)std::count_if(first: first, last: last, pred: UnaryTrue());
72 (void)std::distance(first: first, last: last);
73 (void)std::equal(first1: first, last1: last, first2: first2);
74 (void)std::equal(first1: first, last1: last, first2: first2, binary_pred: 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: first, last: last, val: value);
80 (void)std::equal_range(first: first, last: last, val: value, comp: std::less<void*>());
81 (void)std::fill(first: first, last: last, value: value);
82 (void)std::fill_n(first: first, n: count, value: value);
83 (void)std::find(first: first, last: last, val: value);
84 (void)std::find_end(first1: first, last1: last, first2: first2, last2: mid2);
85 (void)std::find_end(first1: first, last1: last, first2: first2, last2: mid2, comp: std::equal_to<void*>());
86 (void)std::find_if(first: first, last: last, pred: UnaryTrue());
87 (void)std::find_if_not(first: first, last: last, pred: UnaryTrue());
88 (void)std::for_each(first: first, last: last, f: UnaryVoid());
89#if TEST_STD_VER > 14
90 (void)std::for_each_n(first, count, UnaryVoid());
91#endif
92 (void)std::generate(first: first, last: last, gen: NullaryValue());
93 (void)std::generate_n(first: first, n: count, gen: NullaryValue());
94 (void)std::includes(first1: first, last1: last, first2: first2, last2: last2);
95 (void)std::includes(first1: first, last1: last, first2: first2, last2: last2, comp: std::less<void*>());
96 (void)std::is_heap(first: first, last: last);
97 (void)std::is_heap(first: first, last: last, comp: std::less<void*>());
98 (void)std::is_heap_until(first: first, last: last);
99 (void)std::is_heap_until(first: first, last: last, comp: std::less<void*>());
100 (void)std::is_partitioned(first: first, last: last, pred: UnaryTrue());
101 (void)std::is_permutation(first1: first, last1: last, first2: first2);
102 (void)std::is_permutation(first1: first, last1: last, first2: first2, pred: 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: first, last: last);
108 (void)std::is_sorted(first: first, last: last, comp: std::less<void*>());
109 (void)std::is_sorted_until(first: first, last: last);
110 (void)std::is_sorted_until(first: first, last: last, comp: 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(first1: first, last1: last, first2: first2, last2: last2);
115 (void)std::lexicographical_compare(first1: first, last1: last, first2: first2, last2: last2, comp: 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: first, last: last, val: value);
121 (void)std::lower_bound(first: first, last: last, val: value, comp: std::less<void*>());
122 (void)std::make_heap(first: first, last: last);
123 (void)std::make_heap(first: first, last: last, comp: std::less<void*>());
124 (void)std::max(a: value, b: value);
125 (void)std::max(a: value, b: value, comp: 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: first, last: last);
131 (void)std::max_element(first: first, last: last, comp: std::less<void*>());
132 (void)std::merge(first1: first, last1: mid, first2: mid, last2: last, result: first2);
133 (void)std::merge(first1: first, last1: mid, first2: mid, last2: last, result: first2, comp: std::less<void*>());
134 (void)std::min(a: value, b: value);
135 (void)std::min(a: value, b: value, comp: 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: first, last: last);
141 (void)std::min_element(first: first, last: last, comp: std::less<void*>());
142 (void)std::minmax(a: value, b: value);
143 (void)std::minmax(a: value, b: value, comp: 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: first, last: last);
149 (void)std::minmax_element(first: first, last: last, comp: std::less<void*>());
150 (void)std::mismatch(first1: first, last1: last, first2: first2);
151 (void)std::mismatch(first1: first, last1: last, first2: first2, binary_pred: 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: first, last: last, result: first2);
157 (void)std::move_backward(first: first, last: last, result: 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: first, last: last, result_first: first2, result_last: mid2);
168 (void)std::partial_sort_copy(first: first, last: last, result_first: first2, result_last: mid2, comp: std::less<void*>());
169 // RELIES ON ADL SWAP (void)std::partition(first, last, UnaryTrue());
170 (void)std::partition_copy(first: first, last: last, out_true: first2, out_false: last2, pred: UnaryTrue());
171 (void)std::partition_point(first: first, last: last, pred: UnaryTrue());
172 (void)std::pop_heap(first: first, last: last);
173 (void)std::pop_heap(first: first, last: last, comp: 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: first, last: last);
177 (void)std::push_heap(first: first, last: last, comp: std::less<void*>());
178 (void)std::remove(first: first, last: last, value: value);
179 (void)std::remove_copy(first: first, last: last, result: first2, value: value);
180 (void)std::remove_copy_if(first: first, last: last, result: first2, pred: UnaryTrue());
181 (void)std::remove_if(first: first, last: last, pred: UnaryTrue());
182 (void)std::replace(first: first, last: last, old_value: value, new_value: value);
183 (void)std::replace_copy(first: first, last: last, result: first2, old_value: value, new_value: value);
184 (void)std::replace_copy_if(first: first, last: last, result: first2, pred: UnaryTrue(), new_value: value);
185 (void)std::replace_if(first: first, last: last, pred: UnaryTrue(), new_value: value);
186 // RELIES ON ADL SWAP (void)std::reverse(first, last);
187 (void)std::reverse_copy(first: first, last: last, result: first2);
188 // RELIES ON ADL SWAP (void)std::rotate(first, mid, last);
189 (void)std::rotate_copy(first: first, middle: mid, last: last, result: first2);
190 (void)std::search(first1: first, last1: last, first2: first2, last2: mid2);
191 (void)std::search(first1: first, last1: last, first2: first2, last2: mid2, predicate: std::equal_to<void*>());
192 (void)std::search_n(first: first, last: last, count: count, val: value);
193 (void)std::search_n(first: first, last: last, count: count, val: value, binary_pred: std::equal_to<void*>());
194 (void)std::set_difference(first1: first, last1: mid, first2: mid, last2: last, result: first2);
195 (void)std::set_difference(first1: first, last1: mid, first2: mid, last2: last, result: first2, comp: std::less<void*>());
196 (void)std::set_intersection(first1: first, last1: mid, first2: mid, last2: last, result: first2);
197 (void)std::set_intersection(first1: first, last1: mid, first2: mid, last2: last, result: first2, comp: std::less<void*>());
198 (void)std::set_symmetric_difference(first1: first, last1: mid, first2: mid, last2: last, result: first2);
199 (void)std::set_symmetric_difference(first1: first, last1: mid, first2: mid, last2: last, result: first2, comp: std::less<void*>());
200 (void)std::set_union(first1: first, last1: mid, first2: mid, last2: last, result: first2);
201 (void)std::set_union(first1: first, last1: mid, first2: mid, last2: last, result: first2, comp: 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: first, last: last);
209 (void)std::sort_heap(first: first, last: last, comp: 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: first, last: last, result: first2, unary_op: UnaryTransform());
215 (void)std::transform(first1: first, last1: mid, first2: mid, result: first2, binary_op: BinaryTransform());
216 (void)std::unique(first: first, last: last);
217 (void)std::unique(first: first, last: last, binary_pred: std::equal_to<void*>());
218 (void)std::unique_copy(first: first, last: last, result: first2);
219 (void)std::unique_copy(first: first, last: last, result: first2, binary_pred: std::equal_to<void*>());
220 (void)std::upper_bound(first: first, last: last, val: value);
221 (void)std::upper_bound(first: first, last: last, val: value, comp: std::less<void*>());
222
223 return true;
224}
225
226void test()
227{
228 all_the_algorithms();
229#if TEST_STD_VER > 17
230 static_assert(all_the_algorithms());
231#endif
232}
233

source code of libcxx/test/std/algorithms/robust_against_adl.compile.pass.cpp