1 //===----------------------------------------------------------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 // <vector>
11
12 // vector& operator=(vector&& c);
13
14 #include <vector>
15 #include <cassert>
16 #include "../../../MoveOnly.h"
17 #include "test_allocator.h"
18 #include "min_allocator.h"
19 #include "asan_testing.h"
20
main()21 int main()
22 {
23 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
24 {
25 std::vector<MoveOnly, test_allocator<MoveOnly> > l(test_allocator<MoveOnly>(5));
26 std::vector<MoveOnly, test_allocator<MoveOnly> > lo(test_allocator<MoveOnly>(5));
27 for (int i = 1; i <= 3; ++i)
28 {
29 l.push_back(i);
30 lo.push_back(i);
31 }
32 assert(is_contiguous_container_asan_correct(l));
33 assert(is_contiguous_container_asan_correct(lo));
34 std::vector<MoveOnly, test_allocator<MoveOnly> > l2(test_allocator<MoveOnly>(5));
35 l2 = std::move(l);
36 assert(l2 == lo);
37 assert(l.empty());
38 assert(l2.get_allocator() == lo.get_allocator());
39 assert(is_contiguous_container_asan_correct(l2));
40 }
41 {
42 std::vector<MoveOnly, test_allocator<MoveOnly> > l(test_allocator<MoveOnly>(5));
43 std::vector<MoveOnly, test_allocator<MoveOnly> > lo(test_allocator<MoveOnly>(5));
44 assert(is_contiguous_container_asan_correct(l));
45 assert(is_contiguous_container_asan_correct(lo));
46 for (int i = 1; i <= 3; ++i)
47 {
48 l.push_back(i);
49 lo.push_back(i);
50 }
51 assert(is_contiguous_container_asan_correct(l));
52 assert(is_contiguous_container_asan_correct(lo));
53 std::vector<MoveOnly, test_allocator<MoveOnly> > l2(test_allocator<MoveOnly>(6));
54 l2 = std::move(l);
55 assert(l2 == lo);
56 assert(!l.empty());
57 assert(l2.get_allocator() == test_allocator<MoveOnly>(6));
58 assert(is_contiguous_container_asan_correct(l2));
59 }
60 {
61 std::vector<MoveOnly, other_allocator<MoveOnly> > l(other_allocator<MoveOnly>(5));
62 std::vector<MoveOnly, other_allocator<MoveOnly> > lo(other_allocator<MoveOnly>(5));
63 assert(is_contiguous_container_asan_correct(l));
64 assert(is_contiguous_container_asan_correct(lo));
65 for (int i = 1; i <= 3; ++i)
66 {
67 l.push_back(i);
68 lo.push_back(i);
69 }
70 assert(is_contiguous_container_asan_correct(l));
71 assert(is_contiguous_container_asan_correct(lo));
72 std::vector<MoveOnly, other_allocator<MoveOnly> > l2(other_allocator<MoveOnly>(6));
73 l2 = std::move(l);
74 assert(l2 == lo);
75 assert(l.empty());
76 assert(l2.get_allocator() == lo.get_allocator());
77 assert(is_contiguous_container_asan_correct(l2));
78 }
79 #if __cplusplus >= 201103L
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 #endif
100 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
101 }
102