Skip to content

Commit 1108295

Browse files
committed
Use LIBCPP_ASSERT for portability
1 parent db60473 commit 1108295

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

libcxx/test/std/containers/sequences/vector.bool/shrink_to_fit.pass.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,11 @@ TEST_CONSTEXPR_CXX20 bool tests() {
2626
using C = std::vector<bool>;
2727
C v(100);
2828
v.push_back(1);
29+
C::size_type before_cap = v.capacity();
2930
v.clear();
3031
v.shrink_to_fit();
31-
assert(v.capacity() == 0);
32+
assert(v.capacity() <= before_cap);
33+
LIBCPP_ASSERT(v.capacity() == 0); // libc++ honors the shrink_to_fit request as a QOI matter
3234
assert(v.size() == 0);
3335
}
3436
{
@@ -40,6 +42,11 @@ TEST_CONSTEXPR_CXX20 bool tests() {
4042
assert(v.capacity() >= 101);
4143
assert(v.capacity() <= before_cap);
4244
assert(v.size() == 101);
45+
v.erase(v.begin() + 1, v.end());
46+
v.shrink_to_fit();
47+
assert(v.capacity() <= before_cap);
48+
LIBCPP_ASSERT(v.capacity() == C(1).capacity()); // libc++ honors the shrink_to_fit request as a QOI matter.
49+
assert(v.size() == 1);
4350
}
4451

4552
#if defined(_LIBCPP_VERSION)

0 commit comments

Comments
 (0)