Skip to content

Commit 4955fb0

Browse files
committed
Run constexpr test with unique_ptr only since C++23
1 parent d4c5dad commit 4955fb0

File tree

2 files changed

+48
-28
lines changed

2 files changed

+48
-28
lines changed

libcxx/test/std/algorithms/alg.modifying.operations/alg.swap/swap_ranges.pass.cpp

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@
2626
struct TestPtr {
2727
template <class Iter>
2828
TEST_CONSTEXPR_CXX20 void operator()() {
29-
types::for_each(types::forward_iterator_list<int*>(), TestPtrImpl<Iter>());
29+
types::for_each(types::forward_iterator_list<int*>(), TestImpl<Iter>());
3030
}
3131

3232
template <class Iter1>
33-
struct TestPtrImpl {
33+
struct TestImpl {
3434
template <class Iter2>
3535
TEST_CONSTEXPR_CXX20 void operator()() {
3636
int a[] = {1, 2, 3};
@@ -46,12 +46,12 @@ struct TestPtr {
4646
#if TEST_STD_VER >= 11
4747
struct TestUniquePtr {
4848
template <class Iter>
49-
TEST_CONSTEXPR_CXX20 void operator()() {
50-
types::for_each(types::forward_iterator_list<std::unique_ptr<int>*>(), TestUniquePtrImpl<Iter>());
49+
TEST_CONSTEXPR_CXX23 void operator()() {
50+
types::for_each(types::forward_iterator_list<std::unique_ptr<int>*>(), TestImpl<Iter>());
5151
}
5252

5353
template <class Iter1>
54-
struct TestUniquePtrImpl {
54+
struct TestImpl {
5555
template <class Iter2>
5656
TEST_CONSTEXPR_CXX23 void operator()() {
5757
std::unique_ptr<int> a[3];
@@ -67,6 +67,12 @@ struct TestUniquePtr {
6767
}
6868
};
6969
};
70+
71+
// This test is constexpr only since C++23 because constexpr std::unique_ptr is only available since C++23
72+
TEST_CONSTEXPR_CXX23 bool test_unique_ptr() {
73+
types::for_each(types::forward_iterator_list<std::unique_ptr<int>*>(), TestUniquePtr());
74+
return true;
75+
}
7076
#endif
7177

7278
TEST_CONSTEXPR_CXX20 bool test_simple_cases() {
@@ -95,19 +101,22 @@ TEST_CONSTEXPR_CXX20 bool test_simple_cases() {
95101
return true;
96102
}
97103

98-
TEST_CONSTEXPR_CXX20 bool tests() {
104+
TEST_CONSTEXPR_CXX20 bool test() {
99105
test_simple_cases();
100106
types::for_each(types::forward_iterator_list<int*>(), TestPtr());
101-
#if TEST_STD_VER >= 11
102-
types::for_each(types::forward_iterator_list<std::unique_ptr<int>*>(), TestUniquePtr());
103-
#endif
104107
return true;
105108
}
106109

107110
int main(int, char**) {
108-
tests();
111+
test();
112+
#if TEST_STD_VER >= 11
113+
test_unique_ptr();
114+
#endif
109115
#if TEST_STD_VER >= 20
110-
static_assert(tests());
116+
static_assert(test());
117+
#endif
118+
#if TEST_STD_VER >= 23
119+
static_assert(test_unique_ptr());
111120
#endif
112121

113122
return 0;

libcxx/test/std/utilities/utility/utility.swap/swap_array.pass.cpp

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,26 @@ constexpr bool can_swap() {
5151
}
5252
#endif
5353

54+
#if TEST_STD_VER >= 11
55+
// This test is constexpr only since C++23 because constexpr std::unique_ptr is only available since C++23
56+
TEST_CONSTEXPR_CXX23 bool test_unique_ptr() {
57+
std::unique_ptr<int> i[3];
58+
for (int k = 0; k < 3; ++k)
59+
i[k].reset(new int(k + 1));
60+
std::unique_ptr<int> j[3];
61+
for (int k = 0; k < 3; ++k)
62+
j[k].reset(new int(k + 4));
63+
std::swap(i, j);
64+
assert(*i[0] == 4);
65+
assert(*i[1] == 5);
66+
assert(*i[2] == 6);
67+
assert(*j[0] == 1);
68+
assert(*j[1] == 2);
69+
assert(*j[2] == 3);
70+
return true;
71+
}
72+
#endif
73+
5474
TEST_CONSTEXPR_CXX20 bool test() {
5575
{
5676
int i[3] = {1, 2, 3};
@@ -107,21 +127,6 @@ TEST_CONSTEXPR_CXX20 bool test() {
107127
assert(b[2][2] == 8);
108128
}
109129
#if TEST_STD_VER >= 11
110-
{
111-
std::unique_ptr<int> i[3];
112-
for (int k = 0; k < 3; ++k)
113-
i[k].reset(new int(k + 1));
114-
std::unique_ptr<int> j[3];
115-
for (int k = 0; k < 3; ++k)
116-
j[k].reset(new int(k + 4));
117-
std::swap(i, j);
118-
assert(*i[0] == 4);
119-
assert(*i[1] == 5);
120-
assert(*i[2] == 6);
121-
assert(*j[0] == 1);
122-
assert(*j[1] == 2);
123-
assert(*j[2] == 3);
124-
}
125130
{
126131
using CA = CopyOnly[42];
127132
using MA = NoexceptMoveOnly[42];
@@ -142,9 +147,15 @@ TEST_CONSTEXPR_CXX20 bool test() {
142147

143148
int main(int, char**) {
144149
test();
145-
#if TEST_STD_VER > 17
150+
#if TEST_STD_VER >= 11
151+
test_unique_ptr();
152+
#endif
153+
#if TEST_STD_VER >= 20
146154
static_assert(test());
147-
#endif // TEST_STD_VER > 17
155+
#endif
156+
#if TEST_STD_VER >= 23
157+
static_assert(test_unique_ptr());
158+
#endif
148159

149160
return 0;
150161
}

0 commit comments

Comments
 (0)