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 resize(size_type sz); |
12 | |
13 | #include <vector> |
14 | #include <cassert> |
15 | |
16 | #include "test_macros.h" |
17 | #include "test_allocator.h" |
18 | #include "MoveOnly.h" |
19 | #include "min_allocator.h" |
20 | #include "asan_testing.h" |
21 | |
22 | TEST_CONSTEXPR_CXX20 bool tests() { |
23 | { |
24 | std::vector<int> v(100); |
25 | v.resize(new_size: 50); |
26 | assert(v.size() == 50); |
27 | assert(v.capacity() == 100); |
28 | assert(is_contiguous_container_asan_correct(v)); |
29 | v.resize(new_size: 200); |
30 | assert(v.size() == 200); |
31 | assert(v.capacity() >= 200); |
32 | assert(is_contiguous_container_asan_correct(v)); |
33 | } |
34 | { |
35 | // Add 1 for implementations that dynamically allocate a container proxy. |
36 | std::vector<int, limited_allocator<int, 300 + 1> > v(100); |
37 | v.resize(50); |
38 | assert(v.size() == 50); |
39 | assert(v.capacity() == 100); |
40 | assert(is_contiguous_container_asan_correct(v)); |
41 | v.resize(200); |
42 | assert(v.size() == 200); |
43 | assert(v.capacity() >= 200); |
44 | assert(is_contiguous_container_asan_correct(v)); |
45 | } |
46 | #if TEST_STD_VER >= 11 |
47 | { |
48 | std::vector<MoveOnly> v(100); |
49 | v.resize(50); |
50 | assert(v.size() == 50); |
51 | assert(v.capacity() == 100); |
52 | assert(is_contiguous_container_asan_correct(v)); |
53 | v.resize(200); |
54 | assert(v.size() == 200); |
55 | assert(v.capacity() >= 200); |
56 | assert(is_contiguous_container_asan_correct(v)); |
57 | } |
58 | { |
59 | // Add 1 for implementations that dynamically allocate a container proxy. |
60 | std::vector<MoveOnly, limited_allocator<MoveOnly, 300 + 1> > v(100); |
61 | v.resize(50); |
62 | assert(v.size() == 50); |
63 | assert(v.capacity() == 100); |
64 | assert(is_contiguous_container_asan_correct(v)); |
65 | v.resize(200); |
66 | assert(v.size() == 200); |
67 | assert(v.capacity() >= 200); |
68 | assert(is_contiguous_container_asan_correct(v)); |
69 | } |
70 | { |
71 | std::vector<MoveOnly, min_allocator<MoveOnly>> v(100); |
72 | v.resize(50); |
73 | assert(v.size() == 50); |
74 | assert(v.capacity() == 100); |
75 | assert(is_contiguous_container_asan_correct(v)); |
76 | v.resize(200); |
77 | assert(v.size() == 200); |
78 | assert(v.capacity() >= 200); |
79 | assert(is_contiguous_container_asan_correct(v)); |
80 | } |
81 | { |
82 | std::vector<int, safe_allocator<int>> v(100); |
83 | v.resize(50); |
84 | assert(v.size() == 50); |
85 | assert(v.capacity() == 100); |
86 | assert(is_contiguous_container_asan_correct(v)); |
87 | v.resize(200); |
88 | assert(v.size() == 200); |
89 | assert(v.capacity() >= 200); |
90 | assert(is_contiguous_container_asan_correct(v)); |
91 | } |
92 | #endif |
93 | |
94 | return true; |
95 | } |
96 | |
97 | int main(int, char**) |
98 | { |
99 | tests(); |
100 | |
101 | #if TEST_STD_VER > 17 |
102 | static_assert(tests()); |
103 | #endif |
104 | |
105 | return 0; |
106 | } |
107 | |