[PowerPC][NFC] Cleanup PPCCTRLoopsVerify pass
[llvm-project.git] / libcxx / test / std / strings / basic.string / string.capacity / reserve_size.pass.cpp
blob8820ad5a14b00d2fcca8974a391739a44244d0af
1 //===----------------------------------------------------------------------===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
9 // <string>
11 // void reserve(size_type res_arg);
13 // This test relies on https://llvm.org/PR45368 being fixed, which isn't in
14 // older Apple dylibs
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
24 #include <string>
25 #include <stdexcept>
26 #include <cassert>
28 #include "test_macros.h"
29 #include "min_allocator.h"
31 template <class S>
32 void
33 test(typename S::size_type min_cap, typename S::size_type erased_index, typename S::size_type res_arg)
35 S s(min_cap, 'a');
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.
40 #if TEST_STD_VER > 17
41 typename S::size_type old_cap = s.capacity();
42 #endif
43 S s0 = s;
44 if (res_arg <= s.max_size())
46 s.reserve(res_arg);
47 LIBCPP_ASSERT(s.__invariants());
48 assert(s == s0);
49 assert(s.capacity() >= res_arg);
50 assert(s.capacity() >= s.size());
51 #if TEST_STD_VER > 17
52 assert(s.capacity() >= old_cap); // reserve never shrinks as of P0966 (C++20)
53 #endif
55 #ifndef TEST_HAS_NO_EXCEPTIONS
56 else
58 try
60 s.reserve(res_arg);
61 LIBCPP_ASSERT(s.__invariants());
62 assert(false);
64 catch (std::length_error&)
66 assert(res_arg > s.max_size());
69 #endif
72 int main(int, char**)
75 typedef std::string S;
77 test<S>(0, 0, 5);
78 test<S>(0, 0, 10);
79 test<S>(0, 0, 50);
82 test<S>(100, 50, 5);
83 test<S>(100, 50, 10);
84 test<S>(100, 50, 50);
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;
94 test<S>(0, 0, 5);
95 test<S>(0, 0, 10);
96 test<S>(0, 0, 50);
99 test<S>(100, 50, 5);
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);
107 #endif
109 return 0;