| 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 | 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 | l.push_back(i); |
| 31 | lo.push_back(i); |
| 32 | } |
| 33 | assert(is_contiguous_container_asan_correct(l)); |
| 34 | assert(is_contiguous_container_asan_correct(lo)); |
| 35 | std::vector<MoveOnly, test_allocator<MoveOnly> > l2(std::move(l), test_allocator<MoveOnly>(6)); |
| 36 | assert(l2 == lo); |
| 37 | assert(!l.empty()); |
| 38 | assert(l2.get_allocator() == test_allocator<MoveOnly>(6)); |
| 39 | assert(is_contiguous_container_asan_correct(l2)); |
| 40 | } |
| 41 | { |
| 42 | std::vector<MoveOnly, test_allocator<MoveOnly> > l(test_allocator<MoveOnly>(5)); |
| 43 | std::vector<MoveOnly, test_allocator<MoveOnly> > lo(test_allocator<MoveOnly>(5)); |
| 44 | assert(is_contiguous_container_asan_correct(l)); |
| 45 | assert(is_contiguous_container_asan_correct(lo)); |
| 46 | for (int i = 1; i <= 3; ++i) { |
| 47 | l.push_back(i); |
| 48 | lo.push_back(i); |
| 49 | } |
| 50 | assert(is_contiguous_container_asan_correct(l)); |
| 51 | assert(is_contiguous_container_asan_correct(lo)); |
| 52 | std::vector<MoveOnly, test_allocator<MoveOnly> > l2(std::move(l), test_allocator<MoveOnly>(5)); |
| 53 | assert(l2 == lo); |
| 54 | assert(l.empty()); |
| 55 | assert(l2.get_allocator() == test_allocator<MoveOnly>(5)); |
| 56 | assert(is_contiguous_container_asan_correct(l2)); |
| 57 | } |
| 58 | { |
| 59 | std::vector<MoveOnly, other_allocator<MoveOnly> > l(other_allocator<MoveOnly>(5)); |
| 60 | std::vector<MoveOnly, other_allocator<MoveOnly> > lo(other_allocator<MoveOnly>(5)); |
| 61 | assert(is_contiguous_container_asan_correct(l)); |
| 62 | assert(is_contiguous_container_asan_correct(lo)); |
| 63 | for (int i = 1; i <= 3; ++i) { |
| 64 | l.push_back(i); |
| 65 | lo.push_back(i); |
| 66 | } |
| 67 | assert(is_contiguous_container_asan_correct(l)); |
| 68 | assert(is_contiguous_container_asan_correct(lo)); |
| 69 | std::vector<MoveOnly, other_allocator<MoveOnly> > l2(std::move(l), other_allocator<MoveOnly>(4)); |
| 70 | assert(l2 == lo); |
| 71 | assert(!l.empty()); |
| 72 | assert(l2.get_allocator() == other_allocator<MoveOnly>(4)); |
| 73 | assert(is_contiguous_container_asan_correct(l2)); |
| 74 | } |
| 75 | { |
| 76 | std::vector<MoveOnly, min_allocator<MoveOnly> > l((min_allocator<MoveOnly>())); |
| 77 | std::vector<MoveOnly, min_allocator<MoveOnly> > lo((min_allocator<MoveOnly>())); |
| 78 | assert(is_contiguous_container_asan_correct(l)); |
| 79 | assert(is_contiguous_container_asan_correct(lo)); |
| 80 | for (int i = 1; i <= 3; ++i) { |
| 81 | l.push_back(i); |
| 82 | lo.push_back(i); |
| 83 | } |
| 84 | assert(is_contiguous_container_asan_correct(l)); |
| 85 | assert(is_contiguous_container_asan_correct(lo)); |
| 86 | std::vector<MoveOnly, min_allocator<MoveOnly> > l2(std::move(l), min_allocator<MoveOnly>()); |
| 87 | assert(l2 == lo); |
| 88 | assert(l.empty()); |
| 89 | assert(l2.get_allocator() == min_allocator<MoveOnly>()); |
| 90 | assert(is_contiguous_container_asan_correct(l2)); |
| 91 | } |
| 92 | { |
| 93 | std::vector<MoveOnly, safe_allocator<MoveOnly> > l((safe_allocator<MoveOnly>())); |
| 94 | std::vector<MoveOnly, safe_allocator<MoveOnly> > lo((safe_allocator<MoveOnly>())); |
| 95 | assert(is_contiguous_container_asan_correct(l)); |
| 96 | assert(is_contiguous_container_asan_correct(lo)); |
| 97 | for (int i = 1; i <= 3; ++i) { |
| 98 | l.push_back(i); |
| 99 | lo.push_back(i); |
| 100 | } |
| 101 | assert(is_contiguous_container_asan_correct(l)); |
| 102 | assert(is_contiguous_container_asan_correct(lo)); |
| 103 | std::vector<MoveOnly, safe_allocator<MoveOnly> > l2(std::move(l), safe_allocator<MoveOnly>()); |
| 104 | assert(l2 == lo); |
| 105 | assert(l.empty()); |
| 106 | assert(l2.get_allocator() == safe_allocator<MoveOnly>()); |
| 107 | assert(is_contiguous_container_asan_correct(l2)); |
| 108 | } |
| 109 | |
| 110 | return true; |
| 111 | } |
| 112 | |
| 113 | int main(int, char**) { |
| 114 | tests(); |
| 115 | #if TEST_STD_VER > 17 |
| 116 | static_assert(tests()); |
| 117 | #endif |
| 118 | return 0; |
| 119 | } |
| 120 | |