Skip to content

Commit cba43ce

Browse files
committed
Avoid inlining test_unique_ptr() in test() due to constexpr limitations
1 parent 892af90 commit cba43ce

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed

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

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,22 @@ template <class Tp>
4949
constexpr bool can_swap() {
5050
return std::is_same<decltype(can_swap_test<Tp>(0)), void>::value;
5151
}
52+
53+
TEST_CONSTEXPR_CXX23 void test_unique_ptr() {
54+
std::unique_ptr<int> i[3];
55+
for (int k = 0; k < 3; ++k)
56+
i[k].reset(new int(k + 1));
57+
std::unique_ptr<int> j[3];
58+
for (int k = 0; k < 3; ++k)
59+
j[k].reset(new int(k + 4));
60+
std::swap(i, j);
61+
assert(*i[0] == 4);
62+
assert(*i[1] == 5);
63+
assert(*i[2] == 6);
64+
assert(*j[0] == 1);
65+
assert(*j[1] == 2);
66+
assert(*j[2] == 3);
67+
}
5268
#endif
5369

5470
TEST_CONSTEXPR_CXX20 bool test() {
@@ -121,22 +137,10 @@ TEST_CONSTEXPR_CXX20 bool test() {
121137
static_assert(noexcept(std::swap(ma, ma)), "");
122138
}
123139

124-
// We can't test unique_ptr in constant evaluation before C++23 as it's constexpr only since C++23.
125-
if (TEST_STD_VER >= 23 || !TEST_IS_CONSTANT_EVALUATED) {
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-
}
140+
// `unique_ptr` is constexpr only since C++23, so we can't inline `test_unique_ptr()` into `test()`
141+
// because `test()` is constexpr since C++20.
142+
if (TEST_STD_VER >= 23 || !TEST_IS_CONSTANT_EVALUATED)
143+
test_unique_ptr();
140144
#endif
141145

142146
return true;

0 commit comments

Comments
 (0)