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++03 && !stdlib=libc++
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
23TEST_CONSTEXPR_CXX20 bool tests() {
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 {
80 std::vector<MoveOnly, min_allocator<MoveOnly> > l((min_allocator<MoveOnly>()));
81 std::vector<MoveOnly, min_allocator<MoveOnly> > lo((min_allocator<MoveOnly>()));
82 assert(is_contiguous_container_asan_correct(l));
83 assert(is_contiguous_container_asan_correct(lo));
84 for (int i = 1; i <= 3; ++i)
85 {
86 l.push_back(i);
87 lo.push_back(i);
88 }
89 assert(is_contiguous_container_asan_correct(l));
90 assert(is_contiguous_container_asan_correct(lo));
91 std::vector<MoveOnly, min_allocator<MoveOnly> > l2((min_allocator<MoveOnly>()));
92 l2 = std::move(l);
93 assert(l2 == lo);
94 assert(l.empty());
95 assert(l2.get_allocator() == lo.get_allocator());
96 assert(is_contiguous_container_asan_correct(l2));
97 }
98 {
99 std::vector<MoveOnly, safe_allocator<MoveOnly> > l((safe_allocator<MoveOnly>()));
100 std::vector<MoveOnly, safe_allocator<MoveOnly> > lo((safe_allocator<MoveOnly>()));
101 assert(is_contiguous_container_asan_correct(l));
102 assert(is_contiguous_container_asan_correct(lo));
103 for (int i = 1; i <= 3; ++i) {
104 l.push_back(i);
105 lo.push_back(i);
106 }
107 assert(is_contiguous_container_asan_correct(l));
108 assert(is_contiguous_container_asan_correct(lo));
109 std::vector<MoveOnly, safe_allocator<MoveOnly> > l2((safe_allocator<MoveOnly>()));
110 l2 = std::move(l);
111 assert(l2 == lo);
112 assert(l.empty());
113 assert(l2.get_allocator() == lo.get_allocator());
114 assert(is_contiguous_container_asan_correct(l2));
115 }
116
117 return true;
118}
119
120int main(int, char**)
121{
122 tests();
123#if TEST_STD_VER > 17
124 static_assert(tests());
125#endif
126 return 0;
127}
128

source code of libcxx/test/std/containers/sequences/vector/vector.cons/assign_move.pass.cpp