|
19 | 19 | #include "asan_testing.h" |
20 | 20 |
|
21 | 21 | TEST_CONSTEXPR_CXX20 bool tests() { |
22 | | - { |
23 | | - std::vector<int> v; |
24 | | - v.reserve(10); |
25 | | - assert(v.capacity() >= 10); |
26 | | - assert(is_contiguous_container_asan_correct(v)); |
27 | | - } |
28 | | - { |
29 | | - std::vector<int> v(100); |
30 | | - assert(v.capacity() == 100); |
31 | | - v.reserve(50); |
32 | | - assert(v.size() == 100); |
33 | | - assert(v.capacity() == 100); |
34 | | - v.reserve(150); |
35 | | - assert(v.size() == 100); |
36 | | - assert(v.capacity() == 150); |
37 | | - assert(is_contiguous_container_asan_correct(v)); |
38 | | - } |
39 | | - { |
40 | | - // Add 1 for implementations that dynamically allocate a container proxy. |
41 | | - std::vector<int, limited_allocator<int, 250 + 1> > v(100); |
42 | | - assert(v.capacity() == 100); |
43 | | - v.reserve(50); |
44 | | - assert(v.size() == 100); |
45 | | - assert(v.capacity() == 100); |
46 | | - v.reserve(150); |
47 | | - assert(v.size() == 100); |
48 | | - assert(v.capacity() == 150); |
49 | | - assert(is_contiguous_container_asan_correct(v)); |
50 | | - } |
51 | | -#ifndef TEST_HAS_NO_EXCEPTIONS |
52 | | - if (!TEST_IS_CONSTANT_EVALUATED) { |
53 | | - std::vector<int> v; |
54 | | - std::size_t sz = v.max_size() + 1; |
55 | | - |
56 | | - try { |
57 | | - v.reserve(sz); |
58 | | - assert(false); |
59 | | - } catch (const std::length_error&) { |
60 | | - assert(v.size() == 0); |
61 | | - assert(v.capacity() == 0); |
62 | | - } |
63 | | - } |
64 | | - if (!TEST_IS_CONSTANT_EVALUATED) { |
65 | | - std::vector<int> v(10, 42); |
66 | | - int* previous_data = v.data(); |
67 | | - std::size_t previous_capacity = v.capacity(); |
68 | | - std::size_t sz = v.max_size() + 1; |
69 | | - |
70 | | - try { |
71 | | - v.reserve(sz); |
72 | | - assert(false); |
73 | | - } catch (std::length_error&) { |
74 | | - assert(v.size() == 10); |
75 | | - assert(v.capacity() == previous_capacity); |
76 | | - assert(v.data() == previous_data); |
77 | | - |
78 | | - for (int i = 0; i < 10; ++i) { |
79 | | - assert(v[i] == 42); |
80 | | - } |
81 | | - } |
82 | | - } |
83 | | -#endif |
| 22 | + { |
| 23 | + std::vector<int> v; |
| 24 | + v.reserve(10); |
| 25 | + assert(v.capacity() >= 10); |
| 26 | + assert(is_contiguous_container_asan_correct(v)); |
| 27 | + } |
| 28 | + { |
| 29 | + std::vector<int> v(100); |
| 30 | + assert(v.capacity() == 100); |
| 31 | + v.reserve(50); |
| 32 | + assert(v.size() == 100); |
| 33 | + assert(v.capacity() == 100); |
| 34 | + v.reserve(150); |
| 35 | + assert(v.size() == 100); |
| 36 | + assert(v.capacity() == 150); |
| 37 | + assert(is_contiguous_container_asan_correct(v)); |
| 38 | + } |
| 39 | + { |
| 40 | + // Add 1 for implementations that dynamically allocate a container proxy. |
| 41 | + std::vector<int, limited_allocator<int, 250 + 1> > v(100); |
| 42 | + assert(v.capacity() == 100); |
| 43 | + v.reserve(50); |
| 44 | + assert(v.size() == 100); |
| 45 | + assert(v.capacity() == 100); |
| 46 | + v.reserve(150); |
| 47 | + assert(v.size() == 100); |
| 48 | + assert(v.capacity() == 150); |
| 49 | + assert(is_contiguous_container_asan_correct(v)); |
| 50 | + } |
84 | 51 | #if TEST_STD_VER >= 11 |
85 | | - { |
86 | | - std::vector<int, min_allocator<int>> v; |
87 | | - v.reserve(10); |
88 | | - assert(v.capacity() >= 10); |
89 | | - assert(is_contiguous_container_asan_correct(v)); |
90 | | - } |
91 | | - { |
92 | | - std::vector<int, min_allocator<int>> v(100); |
93 | | - assert(v.capacity() == 100); |
94 | | - v.reserve(50); |
95 | | - assert(v.size() == 100); |
96 | | - assert(v.capacity() == 100); |
97 | | - v.reserve(150); |
98 | | - assert(v.size() == 100); |
99 | | - assert(v.capacity() == 150); |
100 | | - assert(is_contiguous_container_asan_correct(v)); |
101 | | - } |
102 | | - { |
103 | | - std::vector<int, safe_allocator<int>> v; |
104 | | - v.reserve(10); |
105 | | - assert(v.capacity() >= 10); |
106 | | - assert(is_contiguous_container_asan_correct(v)); |
107 | | - } |
108 | | - { |
109 | | - std::vector<int, safe_allocator<int>> v(100); |
110 | | - assert(v.capacity() == 100); |
111 | | - v.reserve(50); |
112 | | - assert(v.size() == 100); |
113 | | - assert(v.capacity() == 100); |
114 | | - v.reserve(150); |
115 | | - assert(v.size() == 100); |
116 | | - assert(v.capacity() == 150); |
117 | | - assert(is_contiguous_container_asan_correct(v)); |
118 | | - } |
119 | | -#endif |
120 | | -#ifndef TEST_HAS_NO_EXCEPTIONS |
121 | | - if (!TEST_IS_CONSTANT_EVALUATED) { |
122 | | - std::vector<int, limited_allocator<int, 100> > v; |
123 | | - v.reserve(50); |
124 | | - assert(v.capacity() == 50); |
125 | | - assert(is_contiguous_container_asan_correct(v)); |
126 | | - try { |
127 | | - v.reserve(101); |
128 | | - assert(false); |
129 | | - } catch (const std::length_error&) { |
130 | | - // no-op |
131 | | - } |
132 | | - assert(v.capacity() == 50); |
133 | | - assert(is_contiguous_container_asan_correct(v)); |
134 | | - } |
| 52 | + { |
| 53 | + std::vector<int, min_allocator<int>> v; |
| 54 | + v.reserve(10); |
| 55 | + assert(v.capacity() >= 10); |
| 56 | + assert(is_contiguous_container_asan_correct(v)); |
| 57 | + } |
| 58 | + { |
| 59 | + std::vector<int, min_allocator<int>> v(100); |
| 60 | + assert(v.capacity() == 100); |
| 61 | + v.reserve(50); |
| 62 | + assert(v.size() == 100); |
| 63 | + assert(v.capacity() == 100); |
| 64 | + v.reserve(150); |
| 65 | + assert(v.size() == 100); |
| 66 | + assert(v.capacity() == 150); |
| 67 | + assert(is_contiguous_container_asan_correct(v)); |
| 68 | + } |
| 69 | + { |
| 70 | + std::vector<int, safe_allocator<int>> v; |
| 71 | + v.reserve(10); |
| 72 | + assert(v.capacity() >= 10); |
| 73 | + assert(is_contiguous_container_asan_correct(v)); |
| 74 | + } |
| 75 | + { |
| 76 | + std::vector<int, safe_allocator<int>> v(100); |
| 77 | + assert(v.capacity() == 100); |
| 78 | + v.reserve(50); |
| 79 | + assert(v.size() == 100); |
| 80 | + assert(v.capacity() == 100); |
| 81 | + v.reserve(150); |
| 82 | + assert(v.size() == 100); |
| 83 | + assert(v.capacity() == 150); |
| 84 | + assert(is_contiguous_container_asan_correct(v)); |
| 85 | + } |
135 | 86 | #endif |
136 | 87 |
|
137 | | - return true; |
| 88 | + return true; |
138 | 89 | } |
139 | 90 |
|
140 | | -int main(int, char**) |
141 | | -{ |
| 91 | +int main(int, char**) { |
142 | 92 | tests(); |
143 | 93 |
|
144 | 94 | #if TEST_STD_VER > 17 |
|
0 commit comments