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 | |
Marshall Clow | 127db91 | 2015-06-04 00:10:20 +0000 | [diff] [blame] | 12 | // vector(); |
| 13 | // vector(const Alloc&); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 14 | |
| 15 | #include <vector> |
| 16 | #include <cassert> |
| 17 | |
Marshall Clow | c912c0c | 2015-06-04 02:05:41 +0000 | [diff] [blame] | 18 | #include "test_macros.h" |
Marshall Clow | 1b92188 | 2013-12-03 00:18:10 +0000 | [diff] [blame] | 19 | #include "test_allocator.h" |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 20 | #include "../../../NotConstructible.h" |
| 21 | #include "../../../stack_allocator.h" |
Marshall Clow | 061d0cc | 2013-11-26 20:58:02 +0000 | [diff] [blame] | 22 | #include "min_allocator.h" |
Marshall Clow | 1f50f2d | 2014-05-08 14:14:06 +0000 | [diff] [blame] | 23 | #include "asan_testing.h" |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 24 | |
| 25 | template <class C> |
| 26 | void |
| 27 | test0() |
| 28 | { |
Marshall Clow | 127db91 | 2015-06-04 00:10:20 +0000 | [diff] [blame] | 29 | #if TEST_STD_VER > 14 |
| 30 | static_assert((noexcept(C{})), "" ); |
| 31 | #elif TEST_STD_VER >= 11 |
| 32 | static_assert((noexcept(C()) == noexcept(typename C::allocator_type())), "" ); |
| 33 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 34 | C c; |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 35 | assert(c.__invariants()); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 36 | assert(c.empty()); |
| 37 | assert(c.get_allocator() == typename C::allocator_type()); |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 38 | assert(is_contiguous_container_asan_correct(c)); |
Marshall Clow | 127db91 | 2015-06-04 00:10:20 +0000 | [diff] [blame] | 39 | #if TEST_STD_VER >= 11 |
Marshall Clow | 48c7470 | 2014-03-05 19:06:20 +0000 | [diff] [blame] | 40 | C c1 = {}; |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 41 | assert(c1.__invariants()); |
Marshall Clow | 48c7470 | 2014-03-05 19:06:20 +0000 | [diff] [blame] | 42 | assert(c1.empty()); |
| 43 | assert(c1.get_allocator() == typename C::allocator_type()); |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 44 | assert(is_contiguous_container_asan_correct(c1)); |
Marshall Clow | 48c7470 | 2014-03-05 19:06:20 +0000 | [diff] [blame] | 45 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | template <class C> |
| 49 | void |
| 50 | test1(const typename C::allocator_type& a) |
| 51 | { |
Marshall Clow | 127db91 | 2015-06-04 00:10:20 +0000 | [diff] [blame] | 52 | #if TEST_STD_VER > 14 |
| 53 | static_assert((noexcept(C{typename C::allocator_type{}})), "" ); |
| 54 | #elif TEST_STD_VER >= 11 |
| 55 | static_assert((noexcept(C(typename C::allocator_type())) == std::is_nothrow_copy_constructible<typename C::allocator_type>::value), "" ); |
| 56 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 57 | C c(a); |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 58 | assert(c.__invariants()); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 59 | assert(c.empty()); |
| 60 | assert(c.get_allocator() == a); |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 61 | assert(is_contiguous_container_asan_correct(c)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | int main() |
| 65 | { |
| 66 | { |
| 67 | test0<std::vector<int> >(); |
| 68 | test0<std::vector<NotConstructible> >(); |
| 69 | test1<std::vector<int, test_allocator<int> > >(test_allocator<int>(3)); |
| 70 | test1<std::vector<NotConstructible, test_allocator<NotConstructible> > > |
| 71 | (test_allocator<NotConstructible>(5)); |
| 72 | } |
| 73 | { |
| 74 | std::vector<int, stack_allocator<int, 10> > v; |
| 75 | assert(v.empty()); |
| 76 | } |
Marshall Clow | 127db91 | 2015-06-04 00:10:20 +0000 | [diff] [blame] | 77 | #if TEST_STD_VER >= 11 |
Howard Hinnant | 2c39cbe | 2013-06-27 19:35:32 +0000 | [diff] [blame] | 78 | { |
| 79 | test0<std::vector<int, min_allocator<int>> >(); |
| 80 | test0<std::vector<NotConstructible, min_allocator<NotConstructible>> >(); |
| 81 | test1<std::vector<int, min_allocator<int> > >(min_allocator<int>{}); |
| 82 | test1<std::vector<NotConstructible, min_allocator<NotConstructible> > > |
| 83 | (min_allocator<NotConstructible>{}); |
| 84 | } |
| 85 | { |
| 86 | std::vector<int, min_allocator<int> > v; |
| 87 | assert(v.empty()); |
| 88 | } |
| 89 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 90 | } |