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(const vector& v);
13 
14 #include <vector>
15 #include <cassert>
16 
17 #include "test_macros.h"
18 #include "test_allocator.h"
19 #include "min_allocator.h"
20 #include "asan_testing.h"
21 
22 template <class C>
23 void
test(const C & x)24 test(const C& x)
25 {
26     typename C::size_type s = x.size();
27     C c(x);
28     LIBCPP_ASSERT(c.__invariants());
29     assert(c.size() == s);
30     assert(c == x);
31     LIBCPP_ASSERT(is_contiguous_container_asan_correct(c));
32 }
33 
main()34 int main()
35 {
36     {
37         int a[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 8, 7, 6, 5, 4, 3, 1, 0};
38         int* an = a + sizeof(a)/sizeof(a[0]);
39         test(std::vector<int>(a, an));
40     }
41     {
42         std::vector<int, test_allocator<int> > v(3, 2, test_allocator<int>(5));
43         std::vector<int, test_allocator<int> > v2 = v;
44         assert(is_contiguous_container_asan_correct(v));
45         assert(is_contiguous_container_asan_correct(v2));
46         assert(v2 == v);
47         assert(v2.get_allocator() == v.get_allocator());
48         assert(is_contiguous_container_asan_correct(v));
49         assert(is_contiguous_container_asan_correct(v2));
50     }
51 #if TEST_STD_VER >= 11
52     {
53         std::vector<int, other_allocator<int> > v(3, 2, other_allocator<int>(5));
54         std::vector<int, other_allocator<int> > v2 = v;
55         assert(is_contiguous_container_asan_correct(v));
56         assert(is_contiguous_container_asan_correct(v2));
57         assert(v2 == v);
58         assert(v2.get_allocator() == other_allocator<int>(-2));
59         assert(is_contiguous_container_asan_correct(v));
60         assert(is_contiguous_container_asan_correct(v2));
61     }
62     {
63         int a[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 8, 7, 6, 5, 4, 3, 1, 0};
64         int* an = a + sizeof(a)/sizeof(a[0]);
65         test(std::vector<int, min_allocator<int>>(a, an));
66     }
67     {
68         std::vector<int, min_allocator<int> > v(3, 2, min_allocator<int>());
69         std::vector<int, min_allocator<int> > v2 = v;
70         assert(is_contiguous_container_asan_correct(v));
71         assert(is_contiguous_container_asan_correct(v2));
72         assert(v2 == v);
73         assert(v2.get_allocator() == v.get_allocator());
74         assert(is_contiguous_container_asan_correct(v));
75         assert(is_contiguous_container_asan_correct(v2));
76     }
77 #endif
78 }
79