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 reserve(size_type n);
12 
13 #include <vector>
14 #include <cassert>
15 #include "test_allocator.h"
16 #include "min_allocator.h"
17 #include "asan_testing.h"
18 
19 int main(int, char**)
20 {
21     {
22         std::vector<int> v;
23         v.reserve(10);
24         assert(v.capacity() >= 10);
25         assert(is_contiguous_container_asan_correct(v));
26     }
27     {
28         std::vector<int> v(100);
29         assert(v.capacity() == 100);
30         v.reserve(50);
31         assert(v.size() == 100);
32         assert(v.capacity() == 100);
33         v.reserve(150);
34         assert(v.size() == 100);
35         assert(v.capacity() == 150);
36         assert(is_contiguous_container_asan_correct(v));
37     }
38     {
39         // Add 1 for implementations that dynamically allocate a container proxy.
40         std::vector<int, limited_allocator<int, 250 + 1> > v(100);
41         assert(v.capacity() == 100);
42         v.reserve(50);
43         assert(v.size() == 100);
44         assert(v.capacity() == 100);
45         v.reserve(150);
46         assert(v.size() == 100);
47         assert(v.capacity() == 150);
48         assert(is_contiguous_container_asan_correct(v));
49     }
50 #if TEST_STD_VER >= 11
51     {
52         std::vector<int, min_allocator<int>> v;
53         v.reserve(10);
54         assert(v.capacity() >= 10);
55         assert(is_contiguous_container_asan_correct(v));
56     }
57     {
58         std::vector<int, min_allocator<int>> v(100);
59         assert(v.capacity() == 100);
60         v.reserve(50);
61         assert(v.size() == 100);
62         assert(v.capacity() == 100);
63         v.reserve(150);
64         assert(v.size() == 100);
65         assert(v.capacity() == 150);
66         assert(is_contiguous_container_asan_correct(v));
67     }
68 #endif
69 
70   return 0;
71 }
72