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 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: c++98, c++03
13 // vector(vector&& c);
18 #include "test_macros.h"
20 #include "test_allocator.h"
21 #include "min_allocator.h"
22 #include "asan_testing.h"
27 std::vector
<MoveOnly
, test_allocator
<MoveOnly
> > l(test_allocator
<MoveOnly
>(5));
28 std::vector
<MoveOnly
, test_allocator
<MoveOnly
> > lo(test_allocator
<MoveOnly
>(5));
29 assert(is_contiguous_container_asan_correct(l
));
30 assert(is_contiguous_container_asan_correct(lo
));
31 for (int i
= 1; i
<= 3; ++i
)
36 assert(is_contiguous_container_asan_correct(l
));
37 assert(is_contiguous_container_asan_correct(lo
));
38 std::vector
<MoveOnly
, test_allocator
<MoveOnly
> > l2
= std::move(l
);
41 assert(l2
.get_allocator() == lo
.get_allocator());
42 assert(is_contiguous_container_asan_correct(l2
));
45 std::vector
<MoveOnly
, other_allocator
<MoveOnly
> > l(other_allocator
<MoveOnly
>(5));
46 std::vector
<MoveOnly
, other_allocator
<MoveOnly
> > lo(other_allocator
<MoveOnly
>(5));
47 assert(is_contiguous_container_asan_correct(l
));
48 assert(is_contiguous_container_asan_correct(lo
));
49 for (int i
= 1; i
<= 3; ++i
)
54 assert(is_contiguous_container_asan_correct(l
));
55 assert(is_contiguous_container_asan_correct(lo
));
56 std::vector
<MoveOnly
, other_allocator
<MoveOnly
> > l2
= std::move(l
);
59 assert(l2
.get_allocator() == lo
.get_allocator());
60 assert(is_contiguous_container_asan_correct(l2
));
63 int a1
[] = {1, 3, 7, 9, 10};
64 std::vector
<int> c1(a1
, a1
+sizeof(a1
)/sizeof(a1
[0]));
65 assert(is_contiguous_container_asan_correct(c1
));
66 std::vector
<int>::const_iterator i
= c1
.begin();
67 std::vector
<int> c2
= std::move(c1
);
68 assert(is_contiguous_container_asan_correct(c2
));
69 std::vector
<int>::iterator j
= c2
.erase(i
);
71 assert(is_contiguous_container_asan_correct(c2
));
74 std::vector
<MoveOnly
, min_allocator
<MoveOnly
> > l(min_allocator
<MoveOnly
>{});
75 std::vector
<MoveOnly
, min_allocator
<MoveOnly
> > lo(min_allocator
<MoveOnly
>{});
76 assert(is_contiguous_container_asan_correct(l
));
77 assert(is_contiguous_container_asan_correct(lo
));
78 for (int i
= 1; i
<= 3; ++i
)
83 assert(is_contiguous_container_asan_correct(l
));
84 assert(is_contiguous_container_asan_correct(lo
));
85 std::vector
<MoveOnly
, min_allocator
<MoveOnly
> > l2
= std::move(l
);
88 assert(l2
.get_allocator() == lo
.get_allocator());
89 assert(is_contiguous_container_asan_correct(l2
));
92 int a1
[] = {1, 3, 7, 9, 10};
93 std::vector
<int, min_allocator
<int>> c1(a1
, a1
+sizeof(a1
)/sizeof(a1
[0]));
94 assert(is_contiguous_container_asan_correct(c1
));
95 std::vector
<int, min_allocator
<int>>::const_iterator i
= c1
.begin();
96 std::vector
<int, min_allocator
<int>> c2
= std::move(c1
);
97 assert(is_contiguous_container_asan_correct(c2
));
98 std::vector
<int, min_allocator
<int>>::iterator j
= c2
.erase(i
);
100 assert(is_contiguous_container_asan_correct(c2
));
103 test_alloc_base::clear();
104 using Vect
= std::vector
<int, test_allocator
<int> >;
105 Vect
v(test_allocator
<int>(42, 101));
106 assert(test_alloc_base::count
== 1);
107 assert(test_alloc_base::copied
== 1);
108 assert(test_alloc_base::moved
== 0);
110 const test_allocator
<int>& a
= v
.get_allocator();
111 assert(a
.get_data() == 42);
112 assert(a
.get_id() == 101);
114 assert(test_alloc_base::count
== 1);
115 test_alloc_base::clear_ctor_counters();
117 Vect v2
= std::move(v
);
118 assert(test_alloc_base::count
== 2);
119 assert(test_alloc_base::copied
== 0);
120 assert(test_alloc_base::moved
== 1);
122 const test_allocator
<int>& a
= v
.get_allocator();
123 assert(a
.get_id() == test_alloc_base::moved_value
);
124 assert(a
.get_data() == test_alloc_base::moved_value
);
127 const test_allocator
<int>& a
= v2
.get_allocator();
128 assert(a
.get_id() == 101);
129 assert(a
.get_data() == 42);