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(vector&& c, const allocator_type& a);
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 assert(is_contiguous_container_asan_correct(l));
28 assert(is_contiguous_container_asan_correct(lo));
29 for (int i = 1; i <= 3; ++i)
30 {
31 l.push_back(i);
32 lo.push_back(i);
33 }
34 assert(is_contiguous_container_asan_correct(l));
35 assert(is_contiguous_container_asan_correct(lo));
36 std::vector<MoveOnly, test_allocator<MoveOnly> > l2(std::move(l), test_allocator<MoveOnly>(6));
37 assert(l2 == lo);
38 assert(!l.empty());
39 assert(l2.get_allocator() == test_allocator<MoveOnly>(6));
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(std::move(l), test_allocator<MoveOnly>(5));
55 assert(l2 == lo);
56 assert(l.empty());
57 assert(l2.get_allocator() == test_allocator<MoveOnly>(5));
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(std::move(l), other_allocator<MoveOnly>(4));
73 assert(l2 == lo);
74 assert(!l.empty());
75 assert(l2.get_allocator() == other_allocator<MoveOnly>(4));
76 assert(is_contiguous_container_asan_correct(l2));
77 }
78 #if __cplusplus >= 201103L
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 #endif
98 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
99 }
100