1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
11 // template <class T, class Alloc>
12 // void swap(vector<T,Alloc>& x, vector<T,Alloc>& y);
17 #include "test_macros.h"
18 #include "test_allocator.h"
19 #include "min_allocator.h"
20 #include "asan_testing.h"
25 int a1
[] = {1, 3, 7, 9, 10};
26 int a2
[] = {0, 2, 4, 5, 6, 8, 11};
27 std::vector
<int> c1(a1
, a1
+sizeof(a1
)/sizeof(a1
[0]));
28 std::vector
<int> c2(a2
, a2
+sizeof(a2
)/sizeof(a2
[0]));
29 assert(is_contiguous_container_asan_correct(c1
));
30 assert(is_contiguous_container_asan_correct(c2
));
32 assert(c1
== std::vector
<int>(a2
, a2
+sizeof(a2
)/sizeof(a2
[0])));
33 assert(c2
== std::vector
<int>(a1
, a1
+sizeof(a1
)/sizeof(a1
[0])));
34 assert(is_contiguous_container_asan_correct(c1
));
35 assert(is_contiguous_container_asan_correct(c2
));
38 int a1
[] = {1, 3, 7, 9, 10};
39 int a2
[] = {0, 2, 4, 5, 6, 8, 11};
40 std::vector
<int> c1(a1
, a1
);
41 std::vector
<int> c2(a2
, a2
+sizeof(a2
)/sizeof(a2
[0]));
42 assert(is_contiguous_container_asan_correct(c1
));
43 assert(is_contiguous_container_asan_correct(c2
));
45 assert(c1
== std::vector
<int>(a2
, a2
+sizeof(a2
)/sizeof(a2
[0])));
47 assert(distance(c2
.begin(), c2
.end()) == 0);
48 assert(is_contiguous_container_asan_correct(c1
));
49 assert(is_contiguous_container_asan_correct(c2
));
52 int a1
[] = {1, 3, 7, 9, 10};
53 int a2
[] = {0, 2, 4, 5, 6, 8, 11};
54 std::vector
<int> c1(a1
, a1
+sizeof(a1
)/sizeof(a1
[0]));
55 std::vector
<int> c2(a2
, a2
);
56 assert(is_contiguous_container_asan_correct(c1
));
57 assert(is_contiguous_container_asan_correct(c2
));
60 assert(distance(c1
.begin(), c1
.end()) == 0);
61 assert(c2
== std::vector
<int>(a1
, a1
+sizeof(a1
)/sizeof(a1
[0])));
62 assert(is_contiguous_container_asan_correct(c1
));
63 assert(is_contiguous_container_asan_correct(c2
));
66 int a1
[] = {1, 3, 7, 9, 10};
67 int a2
[] = {0, 2, 4, 5, 6, 8, 11};
68 std::vector
<int> c1(a1
, a1
);
69 std::vector
<int> c2(a2
, a2
);
70 assert(is_contiguous_container_asan_correct(c1
));
71 assert(is_contiguous_container_asan_correct(c2
));
74 assert(distance(c1
.begin(), c1
.end()) == 0);
76 assert(distance(c2
.begin(), c2
.end()) == 0);
77 assert(is_contiguous_container_asan_correct(c1
));
78 assert(is_contiguous_container_asan_correct(c2
));
81 int a1
[] = {1, 3, 7, 9, 10};
82 int a2
[] = {0, 2, 4, 5, 6, 8, 11};
83 typedef test_allocator
<int> A
;
84 std::vector
<int, A
> c1(a1
, a1
+sizeof(a1
)/sizeof(a1
[0]), A(1, 1));
85 std::vector
<int, A
> c2(a2
, a2
+sizeof(a2
)/sizeof(a2
[0]), A(1, 2));
87 assert((c1
== std::vector
<int, A
>(a2
, a2
+sizeof(a2
)/sizeof(a2
[0]))));
88 assert(c1
.get_allocator().get_id() == 1);
89 assert((c2
== std::vector
<int, A
>(a1
, a1
+sizeof(a1
)/sizeof(a1
[0]))));
90 assert(c2
.get_allocator().get_id() == 2);
93 int a1
[] = {1, 3, 7, 9, 10};
94 int a2
[] = {0, 2, 4, 5, 6, 8, 11};
95 typedef other_allocator
<int> A
;
96 std::vector
<int, A
> c1(a1
, a1
+sizeof(a1
)/sizeof(a1
[0]), A(1));
97 std::vector
<int, A
> c2(a2
, a2
+sizeof(a2
)/sizeof(a2
[0]), A(2));
98 assert(is_contiguous_container_asan_correct(c1
));
99 assert(is_contiguous_container_asan_correct(c2
));
101 assert((c1
== std::vector
<int, A
>(a2
, a2
+sizeof(a2
)/sizeof(a2
[0]))));
102 assert(c1
.get_allocator() == A(2));
103 assert((c2
== std::vector
<int, A
>(a1
, a1
+sizeof(a1
)/sizeof(a1
[0]))));
104 assert(c2
.get_allocator() == A(1));
105 assert(is_contiguous_container_asan_correct(c1
));
106 assert(is_contiguous_container_asan_correct(c2
));
108 #if TEST_STD_VER >= 11
110 int a1
[] = {1, 3, 7, 9, 10};
111 int a2
[] = {0, 2, 4, 5, 6, 8, 11};
112 std::vector
<int, min_allocator
<int>> c1(a1
, a1
+sizeof(a1
)/sizeof(a1
[0]));
113 std::vector
<int, min_allocator
<int>> c2(a2
, a2
+sizeof(a2
)/sizeof(a2
[0]));
114 assert(is_contiguous_container_asan_correct(c1
));
115 assert(is_contiguous_container_asan_correct(c2
));
117 assert((c1
== std::vector
<int, min_allocator
<int>>(a2
, a2
+sizeof(a2
)/sizeof(a2
[0]))));
118 assert((c2
== std::vector
<int, min_allocator
<int>>(a1
, a1
+sizeof(a1
)/sizeof(a1
[0]))));
119 assert(is_contiguous_container_asan_correct(c1
));
120 assert(is_contiguous_container_asan_correct(c2
));
123 int a1
[] = {1, 3, 7, 9, 10};
124 int a2
[] = {0, 2, 4, 5, 6, 8, 11};
125 std::vector
<int, min_allocator
<int>> c1(a1
, a1
);
126 std::vector
<int, min_allocator
<int>> c2(a2
, a2
+sizeof(a2
)/sizeof(a2
[0]));
127 assert(is_contiguous_container_asan_correct(c1
));
128 assert(is_contiguous_container_asan_correct(c2
));
130 assert((c1
== std::vector
<int, min_allocator
<int>>(a2
, a2
+sizeof(a2
)/sizeof(a2
[0]))));
132 assert(distance(c2
.begin(), c2
.end()) == 0);
133 assert(is_contiguous_container_asan_correct(c1
));
134 assert(is_contiguous_container_asan_correct(c2
));
137 int a1
[] = {1, 3, 7, 9, 10};
138 int a2
[] = {0, 2, 4, 5, 6, 8, 11};
139 std::vector
<int, min_allocator
<int>> c1(a1
, a1
+sizeof(a1
)/sizeof(a1
[0]));
140 std::vector
<int, min_allocator
<int>> c2(a2
, a2
);
141 assert(is_contiguous_container_asan_correct(c1
));
142 assert(is_contiguous_container_asan_correct(c2
));
145 assert(distance(c1
.begin(), c1
.end()) == 0);
146 assert((c2
== std::vector
<int, min_allocator
<int>>(a1
, a1
+sizeof(a1
)/sizeof(a1
[0]))));
147 assert(is_contiguous_container_asan_correct(c1
));
148 assert(is_contiguous_container_asan_correct(c2
));
151 int a1
[] = {1, 3, 7, 9, 10};
152 int a2
[] = {0, 2, 4, 5, 6, 8, 11};
153 std::vector
<int, min_allocator
<int>> c1(a1
, a1
);
154 std::vector
<int, min_allocator
<int>> c2(a2
, a2
);
155 assert(is_contiguous_container_asan_correct(c1
));
156 assert(is_contiguous_container_asan_correct(c2
));
159 assert(distance(c1
.begin(), c1
.end()) == 0);
161 assert(distance(c2
.begin(), c2
.end()) == 0);
162 assert(is_contiguous_container_asan_correct(c1
));
163 assert(is_contiguous_container_asan_correct(c2
));
166 int a1
[] = {1, 3, 7, 9, 10};
167 int a2
[] = {0, 2, 4, 5, 6, 8, 11};
168 typedef min_allocator
<int> A
;
169 std::vector
<int, A
> c1(a1
, a1
+sizeof(a1
)/sizeof(a1
[0]), A());
170 std::vector
<int, A
> c2(a2
, a2
+sizeof(a2
)/sizeof(a2
[0]), A());
171 assert(is_contiguous_container_asan_correct(c1
));
172 assert(is_contiguous_container_asan_correct(c2
));
174 assert((c1
== std::vector
<int, A
>(a2
, a2
+sizeof(a2
)/sizeof(a2
[0]))));
175 assert(c1
.get_allocator() == A());
176 assert((c2
== std::vector
<int, A
>(a1
, a1
+sizeof(a1
)/sizeof(a1
[0]))));
177 assert(c2
.get_allocator() == A());
178 assert(is_contiguous_container_asan_correct(c1
));
179 assert(is_contiguous_container_asan_correct(c2
));