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 // UNSUPPORTED: c++98, c++03
10
11 // <vector>
12
13 // vector& operator=(vector&& c);
14
15 #include <vector>
16 #include <cassert>
17 #include "test_macros.h"
18 #include "MoveOnly.h"
19 #include "test_allocator.h"
20 #include "min_allocator.h"
21 #include "asan_testing.h"
22
main(int,char **)23 int main(int, char**)
24 {
25 {
26 std::vector<MoveOnly, test_allocator<MoveOnly> > l(test_allocator<MoveOnly>(5));
27 std::vector<MoveOnly, test_allocator<MoveOnly> > lo(test_allocator<MoveOnly>(5));
28 for (int i = 1; i <= 3; ++i)
29 {
30 l.push_back(i);
31 lo.push_back(i);
32 }
33 assert(is_contiguous_container_asan_correct(l));
34 assert(is_contiguous_container_asan_correct(lo));
35 std::vector<MoveOnly, test_allocator<MoveOnly> > l2(test_allocator<MoveOnly>(5));
36 l2 = std::move(l);
37 assert(l2 == lo);
38 assert(l.empty());
39 assert(l2.get_allocator() == lo.get_allocator());
40 assert(is_contiguous_container_asan_correct(l2));
41 }
42 {
43 std::vector<MoveOnly, test_allocator<MoveOnly> > l(test_allocator<MoveOnly>(5));
44 std::vector<MoveOnly, test_allocator<MoveOnly> > lo(test_allocator<MoveOnly>(5));
45 assert(is_contiguous_container_asan_correct(l));
46 assert(is_contiguous_container_asan_correct(lo));
47 for (int i = 1; i <= 3; ++i)
48 {
49 l.push_back(i);
50 lo.push_back(i);
51 }
52 assert(is_contiguous_container_asan_correct(l));
53 assert(is_contiguous_container_asan_correct(lo));
54 std::vector<MoveOnly, test_allocator<MoveOnly> > l2(test_allocator<MoveOnly>(6));
55 l2 = std::move(l);
56 assert(l2 == lo);
57 assert(!l.empty());
58 assert(l2.get_allocator() == test_allocator<MoveOnly>(6));
59 assert(is_contiguous_container_asan_correct(l2));
60 }
61 {
62 std::vector<MoveOnly, other_allocator<MoveOnly> > l(other_allocator<MoveOnly>(5));
63 std::vector<MoveOnly, other_allocator<MoveOnly> > lo(other_allocator<MoveOnly>(5));
64 assert(is_contiguous_container_asan_correct(l));
65 assert(is_contiguous_container_asan_correct(lo));
66 for (int i = 1; i <= 3; ++i)
67 {
68 l.push_back(i);
69 lo.push_back(i);
70 }
71 assert(is_contiguous_container_asan_correct(l));
72 assert(is_contiguous_container_asan_correct(lo));
73 std::vector<MoveOnly, other_allocator<MoveOnly> > l2(other_allocator<MoveOnly>(6));
74 l2 = std::move(l);
75 assert(l2 == lo);
76 assert(l.empty());
77 assert(l2.get_allocator() == lo.get_allocator());
78 assert(is_contiguous_container_asan_correct(l2));
79 }
80 {
81 std::vector<MoveOnly, min_allocator<MoveOnly> > l(min_allocator<MoveOnly>{});
82 std::vector<MoveOnly, min_allocator<MoveOnly> > lo(min_allocator<MoveOnly>{});
83 assert(is_contiguous_container_asan_correct(l));
84 assert(is_contiguous_container_asan_correct(lo));
85 for (int i = 1; i <= 3; ++i)
86 {
87 l.push_back(i);
88 lo.push_back(i);
89 }
90 assert(is_contiguous_container_asan_correct(l));
91 assert(is_contiguous_container_asan_correct(lo));
92 std::vector<MoveOnly, min_allocator<MoveOnly> > l2(min_allocator<MoveOnly>{});
93 l2 = std::move(l);
94 assert(l2 == lo);
95 assert(l.empty());
96 assert(l2.get_allocator() == lo.get_allocator());
97 assert(is_contiguous_container_asan_correct(l2));
98 }
99
100 return 0;
101 }
102