Skip to content

Commit 45a13f5

Browse files
Drive-by: Unblock related test coverages in constant evaluation
For `stable_partition`, `ranges::stable_sort`, `std::stable_sort`, `std::stable_partition`, and `std::inplace_merge`.
1 parent f04f69e commit 45a13f5

File tree

3 files changed

+54
-23
lines changed

3 files changed

+54
-23
lines changed

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

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -230,10 +230,19 @@ constexpr bool all_the_algorithms()
230230
(void)std::ranges::sort(a, Less(&copies)); assert(copies == 0);
231231
(void)std::ranges::sort_heap(first, last, Less(&copies)); assert(copies == 0);
232232
(void)std::ranges::sort_heap(a, Less(&copies)); assert(copies == 0);
233-
if (!std::is_constant_evaluated()) { (void)std::ranges::stable_partition(first, last, UnaryTrue(&copies)); assert(copies == 0); }
234-
if (!std::is_constant_evaluated()) { (void)std::ranges::stable_partition(a, UnaryTrue(&copies)); assert(copies == 0); }
235-
if (!std::is_constant_evaluated()) { (void)std::ranges::stable_sort(first, last, Less(&copies)); assert(copies == 0); }
236-
if (!std::is_constant_evaluated()) { (void)std::ranges::stable_sort(a, Less(&copies)); assert(copies == 0); }
233+
#if TEST_STD_VER < 26
234+
if (!std::is_constant_evaluated())
235+
#endif
236+
{
237+
(void)std::ranges::stable_partition(first, last, UnaryTrue(&copies));
238+
assert(copies == 0);
239+
(void)std::ranges::stable_partition(a, UnaryTrue(&copies));
240+
assert(copies == 0);
241+
(void)std::ranges::stable_sort(first, last, Less(&copies));
242+
assert(copies == 0);
243+
(void)std::ranges::stable_sort(a, Less(&copies));
244+
assert(copies == 0);
245+
}
237246
#if TEST_STD_VER > 20
238247
(void)std::ranges::starts_with(first, last, first2, last2, Equal(&copies)); assert(copies == 0);
239248
(void)std::ranges::starts_with(a, b, Equal(&copies)); assert(copies == 0);

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

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -235,10 +235,19 @@ constexpr bool all_the_algorithms()
235235
(void)std::ranges::sort(a, Less(), Proj(&copies)); assert(copies == 0);
236236
(void)std::ranges::sort_heap(first, last, Less(), Proj(&copies)); assert(copies == 0);
237237
(void)std::ranges::sort_heap(a, Less(), Proj(&copies)); assert(copies == 0);
238-
if (!std::is_constant_evaluated()) { (void)std::ranges::stable_partition(first, last, UnaryTrue(), Proj(&copies)); assert(copies == 0); }
239-
if (!std::is_constant_evaluated()) { (void)std::ranges::stable_partition(a, UnaryTrue(), Proj(&copies)); assert(copies == 0); }
240-
if (!std::is_constant_evaluated()) { (void)std::ranges::stable_sort(first, last, Less(), Proj(&copies)); assert(copies == 0); }
241-
if (!std::is_constant_evaluated()) { (void)std::ranges::stable_sort(a, Less(), Proj(&copies)); assert(copies == 0); }
238+
#if TEST_STD_VER < 26
239+
if (!std::is_constant_evaluated())
240+
#endif
241+
{
242+
(void)std::ranges::stable_partition(first, last, UnaryTrue(), Proj(&copies));
243+
assert(copies == 0);
244+
(void)std::ranges::stable_partition(a, UnaryTrue(), Proj(&copies));
245+
assert(copies == 0);
246+
(void)std::ranges::stable_sort(first, last, Less(), Proj(&copies));
247+
assert(copies == 0);
248+
(void)std::ranges::stable_sort(a, Less(), Proj(&copies));
249+
assert(copies == 0);
250+
}
242251
#if TEST_STD_VER > 20
243252
(void)std::ranges::starts_with(first, last, first2, last2, Equal(), Proj(&copies), Proj(&copies)); assert(copies == 0);
244253
(void)std::ranges::starts_with(a, b, Equal(), Proj(&copies), Proj(&copies)); assert(copies == 0);

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

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,36 @@
1515

1616
struct A {
1717
int i = 0;
18-
bool operator<(const A& rhs) const { return i < rhs.i; }
19-
static bool isEven(const A& a) { return a.i % 2 == 0; }
18+
TEST_CONSTEXPR bool operator<(const A& rhs) const { return i < rhs.i; }
19+
static TEST_CONSTEXPR bool isEven(const A& a) { return a.i % 2 == 0; }
2020
};
2121

2222
void *operator new(std::size_t, A*) = delete;
2323

24-
int main(int, char**)
25-
{
26-
A a[4] = {};
27-
std::sort(a, a+4);
28-
std::sort(a, a+4, std::less<A>());
29-
std::partition(a, a+4, A::isEven);
30-
std::stable_sort(a, a+4);
31-
std::stable_sort(a, a+4, std::less<A>());
32-
std::stable_partition(a, a+4, A::isEven);
33-
std::inplace_merge(a, a+2, a+4);
34-
std::inplace_merge(a, a+2, a+4, std::less<A>());
35-
36-
return 0;
24+
TEST_CONSTEXPR_CXX20 bool test() {
25+
A a[4] = {};
26+
std::sort(a, a + 4);
27+
std::sort(a, a + 4, std::less<A>());
28+
std::partition(a, a + 4, A::isEven);
29+
#if TEST_STD_VER < 26
30+
if (!TEST_IS_CONSTANT_EVALUATED)
31+
#endif
32+
{
33+
std::stable_sort(a, a + 4);
34+
std::stable_sort(a, a + 4, std::less<A>());
35+
std::stable_partition(a, a + 4, A::isEven);
36+
std::inplace_merge(a, a + 2, a + 4);
37+
std::inplace_merge(a, a + 2, a + 4, std::less<A>());
38+
}
39+
40+
return true;
41+
}
42+
43+
int main(int, char**) {
44+
test();
45+
#if TEST_STD_VER >= 20
46+
static_assert(test());
47+
#endif
48+
49+
return 0;
3750
}

0 commit comments

Comments
 (0)