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 | // explicit vector(size_type n); |
| 13 | |
| 14 | #include <vector> |
| 15 | #include <cassert> |
| 16 | |
Marshall Clow | e27dbcf | 2013-12-02 17:00:56 +0000 | [diff] [blame] | 17 | #include "DefaultOnly.h" |
Marshall Clow | 061d0cc | 2013-11-26 20:58:02 +0000 | [diff] [blame] | 18 | #include "min_allocator.h" |
Marshall Clow | 1b92188 | 2013-12-03 00:18:10 +0000 | [diff] [blame] | 19 | #include "test_allocator.h" |
Marshall Clow | 1f50f2d | 2014-05-08 14:14:06 +0000 | [diff] [blame] | 20 | #include "asan_testing.h" |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 21 | |
| 22 | template <class C> |
| 23 | void |
Marshall Clow | a49a2c9 | 2013-09-14 00:47:59 +0000 | [diff] [blame] | 24 | test2(typename C::size_type n, typename C::allocator_type const& a = typename C::allocator_type ()) |
| 25 | { |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 26 | #if _LIBCPP_STD_VER > 11 |
Marshall Clow | a49a2c9 | 2013-09-14 00:47:59 +0000 | [diff] [blame] | 27 | C c(n, a); |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 28 | assert(c.__invariants()); |
Marshall Clow | a49a2c9 | 2013-09-14 00:47:59 +0000 | [diff] [blame] | 29 | assert(c.size() == n); |
| 30 | assert(c.get_allocator() == a); |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 31 | assert(is_contiguous_container_asan_correct(c)); |
| 32 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Marshall Clow | a49a2c9 | 2013-09-14 00:47:59 +0000 | [diff] [blame] | 33 | for (typename C::const_iterator i = c.cbegin(), e = c.cend(); i != e; ++i) |
| 34 | assert(*i == typename C::value_type()); |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 35 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Marshall Clow | a49a2c9 | 2013-09-14 00:47:59 +0000 | [diff] [blame] | 36 | #endif |
| 37 | } |
| 38 | |
| 39 | template <class C> |
| 40 | void |
| 41 | test1(typename C::size_type n) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 42 | { |
| 43 | C c(n); |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 44 | assert(c.__invariants()); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 45 | assert(c.size() == n); |
| 46 | assert(c.get_allocator() == typename C::allocator_type()); |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 47 | assert(is_contiguous_container_asan_correct(c)); |
| 48 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 49 | for (typename C::const_iterator i = c.cbegin(), e = c.cend(); i != e; ++i) |
| 50 | assert(*i == typename C::value_type()); |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 51 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 52 | } |
| 53 | |
Marshall Clow | a49a2c9 | 2013-09-14 00:47:59 +0000 | [diff] [blame] | 54 | template <class C> |
| 55 | void |
| 56 | test(typename C::size_type n) |
| 57 | { |
| 58 | test1<C> ( n ); |
| 59 | test2<C> ( n ); |
| 60 | } |
| 61 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 62 | int main() |
| 63 | { |
| 64 | test<std::vector<int> >(50); |
| 65 | test<std::vector<DefaultOnly> >(500); |
| 66 | assert(DefaultOnly::count == 0); |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 67 | #if __cplusplus >= 201103L |
Howard Hinnant | 2c39cbe | 2013-06-27 19:35:32 +0000 | [diff] [blame] | 68 | test<std::vector<int, min_allocator<int>> >(50); |
| 69 | test<std::vector<DefaultOnly, min_allocator<DefaultOnly>> >(500); |
Marshall Clow | a49a2c9 | 2013-09-14 00:47:59 +0000 | [diff] [blame] | 70 | test2<std::vector<DefaultOnly, test_allocator<DefaultOnly>> >( 100, test_allocator<DefaultOnly>(23)); |
Howard Hinnant | 2c39cbe | 2013-06-27 19:35:32 +0000 | [diff] [blame] | 71 | assert(DefaultOnly::count == 0); |
| 72 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 73 | } |