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(vector&& c, const allocator_type& a); |
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 | |
23 | TEST_CONSTEXPR_CXX20 bool tests() |
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 | assert(is_contiguous_container_asan_correct(l)); |
29 | assert(is_contiguous_container_asan_correct(lo)); |
30 | for (int i = 1; i <= 3; ++i) |
31 | { |
32 | l.push_back(i); |
33 | lo.push_back(i); |
34 | } |
35 | assert(is_contiguous_container_asan_correct(l)); |
36 | assert(is_contiguous_container_asan_correct(lo)); |
37 | std::vector<MoveOnly, test_allocator<MoveOnly> > l2(std::move(l), test_allocator<MoveOnly>(6)); |
38 | assert(l2 == lo); |
39 | assert(!l.empty()); |
40 | assert(l2.get_allocator() == test_allocator<MoveOnly>(6)); |
41 | assert(is_contiguous_container_asan_correct(l2)); |
42 | } |
43 | { |
44 | std::vector<MoveOnly, test_allocator<MoveOnly> > l(test_allocator<MoveOnly>(5)); |
45 | std::vector<MoveOnly, test_allocator<MoveOnly> > lo(test_allocator<MoveOnly>(5)); |
46 | assert(is_contiguous_container_asan_correct(l)); |
47 | assert(is_contiguous_container_asan_correct(lo)); |
48 | for (int i = 1; i <= 3; ++i) |
49 | { |
50 | l.push_back(i); |
51 | lo.push_back(i); |
52 | } |
53 | assert(is_contiguous_container_asan_correct(l)); |
54 | assert(is_contiguous_container_asan_correct(lo)); |
55 | std::vector<MoveOnly, test_allocator<MoveOnly> > l2(std::move(l), test_allocator<MoveOnly>(5)); |
56 | assert(l2 == lo); |
57 | assert(l.empty()); |
58 | assert(l2.get_allocator() == test_allocator<MoveOnly>(5)); |
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(std::move(l), other_allocator<MoveOnly>(4)); |
74 | assert(l2 == lo); |
75 | assert(!l.empty()); |
76 | assert(l2.get_allocator() == other_allocator<MoveOnly>(4)); |
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(std::move(l), min_allocator<MoveOnly>()); |
92 | assert(l2 == lo); |
93 | assert(l.empty()); |
94 | assert(l2.get_allocator() == min_allocator<MoveOnly>()); |
95 | assert(is_contiguous_container_asan_correct(l2)); |
96 | } |
97 | { |
98 | std::vector<MoveOnly, safe_allocator<MoveOnly> > l((safe_allocator<MoveOnly>())); |
99 | std::vector<MoveOnly, safe_allocator<MoveOnly> > lo((safe_allocator<MoveOnly>())); |
100 | assert(is_contiguous_container_asan_correct(l)); |
101 | assert(is_contiguous_container_asan_correct(lo)); |
102 | for (int i = 1; i <= 3; ++i) { |
103 | l.push_back(i); |
104 | lo.push_back(i); |
105 | } |
106 | assert(is_contiguous_container_asan_correct(l)); |
107 | assert(is_contiguous_container_asan_correct(lo)); |
108 | std::vector<MoveOnly, safe_allocator<MoveOnly> > l2(std::move(l), safe_allocator<MoveOnly>()); |
109 | assert(l2 == lo); |
110 | assert(l.empty()); |
111 | assert(l2.get_allocator() == safe_allocator<MoveOnly>()); |
112 | assert(is_contiguous_container_asan_correct(l2)); |
113 | } |
114 | |
115 | return true; |
116 | } |
117 | |
118 | int main(int, char**) |
119 | { |
120 | tests(); |
121 | #if TEST_STD_VER > 17 |
122 | static_assert(tests()); |
123 | #endif |
124 | return 0; |
125 | } |
126 | |