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