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);
13 // This test relies on https://llvm.org/PR45368 being fixed, which isn't in
16 // XFAIL: with_system_cxx_lib=macosx10.15
17 // XFAIL: with_system_cxx_lib=macosx10.14
18 // XFAIL: with_system_cxx_lib=macosx10.13
19 // XFAIL: with_system_cxx_lib=macosx10.12
20 // XFAIL: with_system_cxx_lib=macosx10.11
21 // XFAIL: with_system_cxx_lib=macosx10.10
22 // XFAIL: with_system_cxx_lib=macosx10.9
28 #include "test_macros.h"
29 #include "min_allocator.h"
33 test(typename
S::size_type min_cap
, typename
S::size_type erased_index
, typename
S::size_type res_arg
)
36 s
.erase(erased_index
);
37 assert(s
.size() == erased_index
);
38 assert(s
.capacity() >= min_cap
); // Check that we really have at least this capacity.
41 typename
S::size_type old_cap
= s
.capacity();
44 if (res_arg
<= s
.max_size())
47 LIBCPP_ASSERT(s
.__invariants());
49 assert(s
.capacity() >= res_arg
);
50 assert(s
.capacity() >= s
.size());
52 assert(s
.capacity() >= old_cap
); // reserve never shrinks as of P0966 (C++20)
55 #ifndef TEST_HAS_NO_EXCEPTIONS
61 LIBCPP_ASSERT(s
.__invariants());
64 catch (std::length_error
&)
66 assert(res_arg
> s
.max_size());
75 typedef std::string S
;
85 test
<S
>(100, 50, 100);
86 test
<S
>(100, 50, 1000);
87 test
<S
>(100, 50, S::npos
);
90 #if TEST_STD_VER >= 11
92 typedef std::basic_string
<char, std::char_traits
<char>, min_allocator
<char>> S
;
100 test
<S
>(100, 50, 10);
101 test
<S
>(100, 50, 50);
102 test
<S
>(100, 50, 100);
103 test
<S
>(100, 50, 1000);
104 test
<S
>(100, 50, S::npos
);