Skip to content

Commit e409464

Browse files
[libc++][test][NFC] Introduce TEST_STD_AT_LEAST_26_OR_RUNTIME_EVALUATED (#132593)
And use it for test cases that became constant-evaluation-suitable due to P2562R1. `TEST_STD_AT_LEAST_(20|23)_OR_RUNTIME_EVALUATED` are the precedents.
1 parent 73dc2af commit e409464

9 files changed

+27
-75
lines changed

libcxx/test/libcxx/algorithms/ranges_robust_against_copying_comparators.pass.cpp

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -150,10 +150,7 @@ constexpr bool all_the_algorithms()
150150
(void)std::ranges::is_sorted(a, Less(&copies)); assert(copies == 0);
151151
(void)std::ranges::is_sorted_until(first, last, Less(&copies)); assert(copies == 0);
152152
(void)std::ranges::is_sorted_until(a, Less(&copies)); assert(copies == 0);
153-
#if TEST_STD_VER < 26
154-
if (!std::is_constant_evaluated())
155-
#endif
156-
{
153+
if (TEST_STD_AT_LEAST_26_OR_RUNTIME_EVALUATED) {
157154
(void)std::ranges::inplace_merge(first, mid, last, Less(&copies));
158155
assert(copies == 0);
159156
(void)std::ranges::inplace_merge(a, mid, Less(&copies));
@@ -230,10 +227,7 @@ constexpr bool all_the_algorithms()
230227
(void)std::ranges::sort(a, Less(&copies)); assert(copies == 0);
231228
(void)std::ranges::sort_heap(first, last, Less(&copies)); assert(copies == 0);
232229
(void)std::ranges::sort_heap(a, Less(&copies)); assert(copies == 0);
233-
#if TEST_STD_VER < 26
234-
if (!std::is_constant_evaluated())
235-
#endif
236-
{
230+
if (TEST_STD_AT_LEAST_26_OR_RUNTIME_EVALUATED) {
237231
(void)std::ranges::stable_partition(first, last, UnaryTrue(&copies));
238232
assert(copies == 0);
239233
(void)std::ranges::stable_partition(a, UnaryTrue(&copies));

libcxx/test/libcxx/algorithms/ranges_robust_against_copying_projections.pass.cpp

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,7 @@ constexpr bool all_the_algorithms()
147147
(void)std::ranges::is_sorted(a, Less(), Proj(&copies)); assert(copies == 0);
148148
(void)std::ranges::is_sorted_until(first, last, Less(), Proj(&copies)); assert(copies == 0);
149149
(void)std::ranges::is_sorted_until(a, Less(), Proj(&copies)); assert(copies == 0);
150-
#if TEST_STD_VER < 26
151-
if (!std::is_constant_evaluated())
152-
#endif
153-
{
150+
if (TEST_STD_AT_LEAST_26_OR_RUNTIME_EVALUATED) {
154151
(void)std::ranges::inplace_merge(first, mid, last, Less(), Proj(&copies));
155152
assert(copies == 0);
156153
(void)std::ranges::inplace_merge(a, mid, Less(), Proj(&copies));
@@ -235,10 +232,7 @@ constexpr bool all_the_algorithms()
235232
(void)std::ranges::sort(a, Less(), Proj(&copies)); assert(copies == 0);
236233
(void)std::ranges::sort_heap(first, last, Less(), Proj(&copies)); assert(copies == 0);
237234
(void)std::ranges::sort_heap(a, Less(), Proj(&copies)); assert(copies == 0);
238-
#if TEST_STD_VER < 26
239-
if (!std::is_constant_evaluated())
240-
#endif
241-
{
235+
if (TEST_STD_AT_LEAST_26_OR_RUNTIME_EVALUATED) {
242236
(void)std::ranges::stable_partition(first, last, UnaryTrue(), Proj(&copies));
243237
assert(copies == 0);
244238
(void)std::ranges::stable_partition(a, UnaryTrue(), Proj(&copies));

libcxx/test/std/algorithms/ranges_robust_against_dangling.pass.cpp

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -197,25 +197,16 @@ constexpr bool test_all() {
197197
dangling_1st(std::ranges::shuffle, in, rand_gen());
198198
dangling_1st(std::ranges::unique, in);
199199
dangling_1st(std::ranges::partition, in, unary_pred);
200-
#if TEST_STD_VER < 26
201-
if (!std::is_constant_evaluated())
202-
#endif
203-
{
200+
if (TEST_STD_AT_LEAST_26_OR_RUNTIME_EVALUATED) {
204201
dangling_1st(std::ranges::stable_partition, in, unary_pred);
205202
}
206203
dangling_1st(std::ranges::sort, in);
207-
#if TEST_STD_VER < 26
208-
if (!std::is_constant_evaluated())
209-
#endif
210-
{
204+
if (TEST_STD_AT_LEAST_26_OR_RUNTIME_EVALUATED) {
211205
dangling_1st(std::ranges::stable_sort, in);
212206
}
213207
dangling_1st(std::ranges::partial_sort, in, mid);
214208
dangling_1st(std::ranges::nth_element, in, mid);
215-
#if TEST_STD_VER < 26
216-
if (!std::is_constant_evaluated())
217-
#endif
218-
{
209+
if (TEST_STD_AT_LEAST_26_OR_RUNTIME_EVALUATED) {
219210
dangling_1st(std::ranges::inplace_merge, in, mid);
220211
}
221212
dangling_1st(std::ranges::make_heap, in);

libcxx/test/std/algorithms/ranges_robust_against_omitting_invoke.pass.cpp

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -164,25 +164,16 @@ constexpr bool test_all() {
164164
// For `shuffle`, whether the given generator is invoked via `std::invoke` is not observable.
165165
test(std::ranges::unique, in, &Foo::binary_pred, &Bar::val);
166166
test(std::ranges::partition, in, &Foo::unary_pred, &Bar::val);
167-
#if TEST_STD_VER < 26
168-
if (!std::is_constant_evaluated())
169-
#endif
170-
{
167+
if (TEST_STD_AT_LEAST_26_OR_RUNTIME_EVALUATED) {
171168
test(std::ranges::stable_partition, in, &Foo::unary_pred, &Bar::val);
172169
}
173170
test(std::ranges::sort, in, &Foo::binary_pred, &Bar::val);
174-
#if TEST_STD_VER < 26
175-
if (!std::is_constant_evaluated())
176-
#endif
177-
{
171+
if (TEST_STD_AT_LEAST_26_OR_RUNTIME_EVALUATED) {
178172
test(std::ranges::stable_sort, in, &Foo::binary_pred, &Bar::val);
179173
}
180174
test_mid(std::ranges::partial_sort, in, mid, &Foo::binary_pred, &Bar::val);
181175
test_mid(std::ranges::nth_element, in, mid, &Foo::binary_pred, &Bar::val);
182-
#if TEST_STD_VER < 26
183-
if (!std::is_constant_evaluated())
184-
#endif
185-
{
176+
if (TEST_STD_AT_LEAST_26_OR_RUNTIME_EVALUATED) {
186177
test_mid(std::ranges::inplace_merge, in, mid, &Foo::binary_pred, &Bar::val);
187178
}
188179
test(std::ranges::make_heap, in, &Foo::binary_pred, &Bar::val);

libcxx/test/std/algorithms/ranges_robust_against_proxy_iterators.pass.cpp

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -167,25 +167,16 @@ constexpr void run_tests() {
167167
}
168168
test(std::ranges::unique, in);
169169
test(std::ranges::partition, in, unary_pred);
170-
#if TEST_STD_VER < 26
171-
if (!std::is_constant_evaluated())
172-
#endif
173-
{
170+
if (TEST_STD_AT_LEAST_26_OR_RUNTIME_EVALUATED) {
174171
test(std::ranges::stable_partition, in, unary_pred);
175172
}
176173
test(std::ranges::sort, in);
177-
#if TEST_STD_VER < 26
178-
if (!std::is_constant_evaluated())
179-
#endif
180-
{
174+
if (TEST_STD_AT_LEAST_26_OR_RUNTIME_EVALUATED) {
181175
test(std::ranges::stable_sort, in);
182176
}
183177
test_mid(std::ranges::partial_sort, in, mid);
184178
test_mid(std::ranges::nth_element, in, mid);
185-
#if TEST_STD_VER < 26
186-
if (!std::is_constant_evaluated())
187-
#endif
188-
{
179+
if (TEST_STD_AT_LEAST_26_OR_RUNTIME_EVALUATED) {
189180
test_mid(std::ranges::inplace_merge, in, mid);
190181
}
191182
test(std::ranges::make_heap, in);

libcxx/test/std/algorithms/robust_against_adl_on_new.pass.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,7 @@ TEST_CONSTEXPR_CXX20 bool test() {
2626
std::sort(a, a + 4);
2727
std::sort(a, a + 4, std::less<A>());
2828
std::partition(a, a + 4, A::isEven);
29-
#if TEST_STD_VER < 26
30-
if (!TEST_IS_CONSTANT_EVALUATED)
31-
#endif
32-
{
29+
if (TEST_STD_AT_LEAST_26_OR_RUNTIME_EVALUATED) {
3330
std::stable_sort(a, a + 4);
3431
std::stable_sort(a, a + 4, std::less<A>());
3532
std::stable_partition(a, a + 4, A::isEven);

libcxx/test/std/algorithms/robust_against_proxy_iterators_lifetime_bugs.pass.cpp

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -735,18 +735,12 @@ TEST_CONSTEXPR_CXX20 bool test() {
735735
test(simple_in, [&](I b, I e) { (void) std::shuffle(b, e, rand_gen()); });
736736
// TODO: unique
737737
test(simple_in, [&](I b, I e) { (void) std::partition(b, e, is_neg); });
738-
#if TEST_STD_VER < 26
739-
if (!TEST_IS_CONSTANT_EVALUATED)
740-
#endif
741-
{
738+
if (TEST_STD_AT_LEAST_26_OR_RUNTIME_EVALUATED) {
742739
test(simple_in, [&](I b, I e) { (void)std::stable_partition(b, e, is_neg); });
743740
}
744741
if (!TEST_IS_CONSTANT_EVALUATED)
745742
test(sort_test_in, [&](I b, I e) { (void)std::sort(b, e); });
746-
#if TEST_STD_VER < 26
747-
if (!TEST_IS_CONSTANT_EVALUATED)
748-
#endif
749-
{
743+
if (TEST_STD_AT_LEAST_26_OR_RUNTIME_EVALUATED) {
750744
test(sort_test_in, [&](I b, I e) { (void)std::stable_sort(b, e); });
751745
}
752746
// TODO: partial_sort

libcxx/test/std/algorithms/robust_re_difference_type.compile.pass.cpp

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,7 @@ TEST_CONSTEXPR_CXX20 bool all_the_algorithms()
141141
(void)std::is_sorted(first, last, std::less<void*>());
142142
(void)std::is_sorted_until(first, last);
143143
(void)std::is_sorted_until(first, last, std::less<void*>());
144-
#if TEST_STD_VER < 26
145-
if (!TEST_IS_CONSTANT_EVALUATED)
146-
#endif
147-
{
144+
if (TEST_STD_AT_LEAST_26_OR_RUNTIME_EVALUATED) {
148145
(void)std::inplace_merge(first, mid, last);
149146
(void)std::inplace_merge(first, mid, last, std::less<void*>());
150147
}
@@ -245,10 +242,7 @@ TEST_CONSTEXPR_CXX20 bool all_the_algorithms()
245242
(void)std::sort(first, last, std::less<void*>());
246243
(void)std::sort_heap(first, last);
247244
(void)std::sort_heap(first, last, std::less<void*>());
248-
#if TEST_STD_VER < 26
249-
if (!TEST_IS_CONSTANT_EVALUATED)
250-
#endif
251-
{
245+
if (TEST_STD_AT_LEAST_26_OR_RUNTIME_EVALUATED) {
252246
(void)std::stable_partition(first, last, UnaryTrue());
253247
(void)std::stable_sort(first, last);
254248
(void)std::stable_sort(first, last, std::less<void*>());

libcxx/test/support/test_macros.h

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,16 +148,22 @@
148148
# define TEST_IS_CONSTANT_EVALUATED false
149149
#endif
150150

151+
#if TEST_STD_VER >= 20
152+
# define TEST_STD_AT_LEAST_20_OR_RUNTIME_EVALUATED true
153+
#else
154+
# define TEST_STD_AT_LEAST_20_OR_RUNTIME_EVALUATED (!TEST_IS_CONSTANT_EVALUATED)
155+
#endif
156+
151157
#if TEST_STD_VER >= 23
152158
# define TEST_STD_AT_LEAST_23_OR_RUNTIME_EVALUATED true
153159
#else
154160
# define TEST_STD_AT_LEAST_23_OR_RUNTIME_EVALUATED (!TEST_IS_CONSTANT_EVALUATED)
155161
#endif
156162

157-
#if TEST_STD_VER >= 20
158-
# define TEST_STD_AT_LEAST_20_OR_RUNTIME_EVALUATED true
163+
#if TEST_STD_VER >= 26
164+
# define TEST_STD_AT_LEAST_26_OR_RUNTIME_EVALUATED true
159165
#else
160-
# define TEST_STD_AT_LEAST_20_OR_RUNTIME_EVALUATED (!TEST_IS_CONSTANT_EVALUATED)
166+
# define TEST_STD_AT_LEAST_26_OR_RUNTIME_EVALUATED (!TEST_IS_CONSTANT_EVALUATED)
161167
#endif
162168

163169
#if TEST_STD_VER >= 14

0 commit comments

Comments
 (0)