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 //===----------------------------------------------------------------------===//
8 
9 // <vector>
10 
11 // void shrink_to_fit();
12 
13 #include <vector>
14 #include <cassert>
15 #include "test_macros.h"
16 #include "test_allocator.h"
17 #include "min_allocator.h"
18 #include "asan_testing.h"
19 
main(int,char **)20 int main(int, char**)
21 {
22     {
23         std::vector<int> v(100);
24         v.push_back(1);
25         assert(is_contiguous_container_asan_correct(v));
26         v.shrink_to_fit();
27         assert(v.capacity() == 101);
28         assert(v.size() == 101);
29         assert(is_contiguous_container_asan_correct(v));
30     }
31     {
32         std::vector<int, limited_allocator<int, 401> > v(100);
33         v.push_back(1);
34         assert(is_contiguous_container_asan_correct(v));
35         v.shrink_to_fit();
36         assert(v.capacity() == 101);
37         assert(v.size() == 101);
38         assert(is_contiguous_container_asan_correct(v));
39     }
40 #ifndef _LIBCPP_NO_EXCEPTIONS
41     {
42         std::vector<int, limited_allocator<int, 400> > v(100);
43         v.push_back(1);
44         assert(is_contiguous_container_asan_correct(v));
45         v.shrink_to_fit();
46         LIBCPP_ASSERT(v.capacity() == 200); // assumes libc++'s 2x growth factor
47         assert(v.size() == 101);
48         assert(is_contiguous_container_asan_correct(v));
49     }
50 #endif
51 #if TEST_STD_VER >= 11
52     {
53         std::vector<int, min_allocator<int>> v(100);
54         v.push_back(1);
55         assert(is_contiguous_container_asan_correct(v));
56         v.shrink_to_fit();
57         assert(v.capacity() == 101);
58         assert(v.size() == 101);
59         assert(is_contiguous_container_asan_correct(v));
60     }
61 #endif
62 
63   return 0;
64 }
65