Skip to content

Commit bc1b9f8

Browse files
committed
Organize constexpr tests for unique_ptr in a better way
1 parent bfc2ea2 commit bc1b9f8

File tree

2 files changed

+20
-32
lines changed

2 files changed

+20
-32
lines changed

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -124,13 +124,10 @@ TEST_CONSTEXPR_CXX20 bool test() {
124124

125125
types::for_each(types::forward_iterator_list<int*>(), TestPtr());
126126

127-
#if TEST_STD_VER >= 11 && TEST_STD_VER <= 17
128-
types::for_each(types::forward_iterator_list<std::unique_ptr<int>*>(), TestUniquePtr());
129-
#elif TEST_STD_VER == 20
130-
if (!std::is_constant_evaluated())
127+
#if TEST_STD_VER >= 11
128+
// We can't test unique_ptr in constant evaluation before C++23 as it's constexpr only since C++23.
129+
if (!TEST_IS_CONSTANT_EVALUATED || TEST_STD_VER >= 23)
131130
types::for_each(types::forward_iterator_list<std::unique_ptr<int>*>(), TestUniquePtr());
132-
#elif TEST_STD_VER >= 23
133-
types::for_each(types::forward_iterator_list<std::unique_ptr<int>*>(), TestUniquePtr());
134131
#endif
135132

136133
return true;

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

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -51,26 +51,6 @@ 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-
7454
TEST_CONSTEXPR_CXX20 bool test() {
7555
{
7656
int i[3] = {1, 2, 3};
@@ -140,22 +120,33 @@ TEST_CONSTEXPR_CXX20 bool test() {
140120
static_assert(!noexcept(std::swap(ca, ca)), "");
141121
static_assert(noexcept(std::swap(ma, ma)), "");
142122
}
123+
124+
// We can't test unique_ptr in constant evaluation before C++23 as it's constexpr only since C++23.
125+
if (!TEST_IS_CONSTANT_EVALUATED || TEST_STD_VER >= 23) {
126+
std::unique_ptr<int> i[3];
127+
for (int k = 0; k < 3; ++k)
128+
i[k].reset(new int(k + 1));
129+
std::unique_ptr<int> j[3];
130+
for (int k = 0; k < 3; ++k)
131+
j[k].reset(new int(k + 4));
132+
std::swap(i, j);
133+
assert(*i[0] == 4);
134+
assert(*i[1] == 5);
135+
assert(*i[2] == 6);
136+
assert(*j[0] == 1);
137+
assert(*j[1] == 2);
138+
assert(*j[2] == 3);
139+
}
143140
#endif
144141

145142
return true;
146143
}
147144

148145
int main(int, char**) {
149146
test();
150-
#if TEST_STD_VER >= 11
151-
test_unique_ptr();
152-
#endif
153147
#if TEST_STD_VER >= 20
154148
static_assert(test());
155149
#endif
156-
#if TEST_STD_VER >= 23
157-
static_assert(test_unique_ptr());
158-
#endif
159150

160151
return 0;
161152
}

0 commit comments

Comments
 (0)