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 (841132e) being fixed, which isn't in
14 // older Apple dylibs.
15 // XFAIL: using-built-library-before-llvm-12
21 #include "test_macros.h"
22 #include "min_allocator.h"
23 #include "asan_testing.h"
26 TEST_CONSTEXPR_CXX20
void
27 test(typename
S::size_type min_cap
, typename
S::size_type erased_index
, typename
S::size_type res_arg
) {
29 s
.erase(erased_index
);
30 assert(s
.size() == erased_index
);
31 assert(s
.capacity() >= min_cap
); // Check that we really have at least this capacity.
32 LIBCPP_ASSERT(is_string_asan_correct(s
));
35 typename
S::size_type old_cap
= s
.capacity();
38 if (res_arg
<= s
.max_size()) {
40 LIBCPP_ASSERT(s
.__invariants());
42 assert(s
.capacity() >= res_arg
);
43 assert(s
.capacity() >= s
.size());
44 LIBCPP_ASSERT(is_string_asan_correct(s
));
46 assert(s
.capacity() >= old_cap
); // reserve never shrinks as of P0966 (C++20)
49 #ifndef TEST_HAS_NO_EXCEPTIONS
50 else if (!TEST_IS_CONSTANT_EVALUATED
) {
53 LIBCPP_ASSERT(s
.__invariants());
55 } catch (std::length_error
&) {
56 assert(res_arg
> s
.max_size());
63 TEST_CONSTEXPR_CXX20
void test_string() {
74 test
<S
>(100, 50, 100);
75 test
<S
>(100, 50, 1000);
76 test
<S
>(100, 50, S::npos
);
80 TEST_CONSTEXPR_CXX20
bool test() {
81 test_string
<std::string
>();
82 #if TEST_STD_VER >= 11
83 test_string
<std::basic_string
<char, std::char_traits
<char>, min_allocator
<char>>>();
89 int main(int, char**) {
92 static_assert(test());