1 //===----------------------------------------------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
11 // void reserve(size_type res_arg); // constexpr since C++20
13 // This test relies on https://llvm.org/PR45368 being fixed, which isn't in
15 // XFAIL: stdlib=apple-libc++ && target={{.+}}-apple-macosx{{10.9|10.10|10.11|10.12|10.13|10.14|10.15|11.0}}
21 #include "test_macros.h"
22 #include "min_allocator.h"
25 TEST_CONSTEXPR_CXX20
void
26 test(typename
S::size_type min_cap
, typename
S::size_type erased_index
, typename
S::size_type res_arg
) {
28 s
.erase(erased_index
);
29 assert(s
.size() == erased_index
);
30 assert(s
.capacity() >= min_cap
); // Check that we really have at least this capacity.
33 typename
S::size_type old_cap
= s
.capacity();
36 if (res_arg
<= s
.max_size()) {
38 LIBCPP_ASSERT(s
.__invariants());
40 assert(s
.capacity() >= res_arg
);
41 assert(s
.capacity() >= s
.size());
43 assert(s
.capacity() >= old_cap
); // reserve never shrinks as of P0966 (C++20)
46 #ifndef TEST_HAS_NO_EXCEPTIONS
47 else if (!TEST_IS_CONSTANT_EVALUATED
) {
50 LIBCPP_ASSERT(s
.__invariants());
52 } catch (std::length_error
&) {
53 assert(res_arg
> s
.max_size());
60 TEST_CONSTEXPR_CXX20
void test_string() {
70 test
<S
>(100, 50, 100);
71 test
<S
>(100, 50, 1000);
72 test
<S
>(100, 50, S::npos
);
76 TEST_CONSTEXPR_CXX20
bool test() {
77 test_string
<std::string
>();
78 #if TEST_STD_VER >= 11
79 test_string
<std::basic_string
<char, std::char_traits
<char>, min_allocator
<char>>>();
85 int main(int, char**) {
88 static_assert(test());