Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
Howard Hinnant | f5256e1 | 2010-05-11 21:36:01 +0000 | [diff] [blame] | 3 | // The LLVM Compiler Infrastructure |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4 | // |
Howard Hinnant | b64f8b0 | 2010-11-16 22:09:02 +0000 | [diff] [blame] | 5 | // This file is dual licensed under the MIT and the University of Illinois Open |
| 6 | // Source Licenses. See LICENSE.TXT for details. |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | // <vector> |
| 11 | |
| 12 | // vector(const vector& v); |
| 13 | |
| 14 | #include <vector> |
| 15 | #include <cassert> |
Marshall Clow | 1b92188 | 2013-12-03 00:18:10 +0000 | [diff] [blame] | 16 | #include "test_allocator.h" |
Marshall Clow | 061d0cc | 2013-11-26 20:58:02 +0000 | [diff] [blame] | 17 | #include "min_allocator.h" |
Marshall Clow | 1f50f2d | 2014-05-08 14:14:06 +0000 | [diff] [blame] | 18 | #include "asan_testing.h" |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 19 | |
| 20 | template <class C> |
| 21 | void |
| 22 | test(const C& x) |
| 23 | { |
| 24 | unsigned s = x.size(); |
| 25 | C c(x); |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 26 | assert(c.__invariants()); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 27 | assert(c.size() == s); |
| 28 | assert(c == x); |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 29 | assert(is_contiguous_container_asan_correct(c)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 30 | } |
| 31 | |
| 32 | int main() |
| 33 | { |
| 34 | { |
| 35 | int a[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 8, 7, 6, 5, 4, 3, 1, 0}; |
| 36 | int* an = a + sizeof(a)/sizeof(a[0]); |
| 37 | test(std::vector<int>(a, an)); |
| 38 | } |
| 39 | { |
| 40 | std::vector<int, test_allocator<int> > v(3, 2, test_allocator<int>(5)); |
| 41 | std::vector<int, test_allocator<int> > v2 = v; |
Marshall Clow | 1f50f2d | 2014-05-08 14:14:06 +0000 | [diff] [blame] | 42 | assert(is_contiguous_container_asan_correct(v)); |
| 43 | assert(is_contiguous_container_asan_correct(v2)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 44 | assert(v2 == v); |
| 45 | assert(v2.get_allocator() == v.get_allocator()); |
Marshall Clow | 1f50f2d | 2014-05-08 14:14:06 +0000 | [diff] [blame] | 46 | assert(is_contiguous_container_asan_correct(v)); |
| 47 | assert(is_contiguous_container_asan_correct(v2)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 48 | } |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 49 | #ifndef _LIBCPP_HAS_NO_ADVANCED_SFINAE |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 50 | { |
| 51 | std::vector<int, other_allocator<int> > v(3, 2, other_allocator<int>(5)); |
| 52 | std::vector<int, other_allocator<int> > v2 = v; |
Marshall Clow | 1f50f2d | 2014-05-08 14:14:06 +0000 | [diff] [blame] | 53 | assert(is_contiguous_container_asan_correct(v)); |
| 54 | assert(is_contiguous_container_asan_correct(v2)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 55 | assert(v2 == v); |
| 56 | assert(v2.get_allocator() == other_allocator<int>(-2)); |
Marshall Clow | 1f50f2d | 2014-05-08 14:14:06 +0000 | [diff] [blame] | 57 | assert(is_contiguous_container_asan_correct(v)); |
| 58 | assert(is_contiguous_container_asan_correct(v2)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 59 | } |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 60 | #endif // _LIBCPP_HAS_NO_ADVANCED_SFINAE |
| 61 | #if __cplusplus >= 201103L |
Howard Hinnant | 2c39cbe | 2013-06-27 19:35:32 +0000 | [diff] [blame] | 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; |
Marshall Clow | 1f50f2d | 2014-05-08 14:14:06 +0000 | [diff] [blame] | 70 | assert(is_contiguous_container_asan_correct(v)); |
| 71 | assert(is_contiguous_container_asan_correct(v2)); |
Howard Hinnant | 2c39cbe | 2013-06-27 19:35:32 +0000 | [diff] [blame] | 72 | assert(v2 == v); |
| 73 | assert(v2.get_allocator() == v.get_allocator()); |
Marshall Clow | 1f50f2d | 2014-05-08 14:14:06 +0000 | [diff] [blame] | 74 | assert(is_contiguous_container_asan_correct(v)); |
| 75 | assert(is_contiguous_container_asan_correct(v2)); |
Howard Hinnant | 2c39cbe | 2013-06-27 19:35:32 +0000 | [diff] [blame] | 76 | } |
| 77 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 78 | } |