blob: 5e87c07ef70a96b3cdeb59a395f7021c5875af88 [file] [log] [blame]
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001//===----------------------------------------------------------------------===//
2//
Howard Hinnantf5256e12010-05-11 21:36:01 +00003// The LLVM Compiler Infrastructure
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004//
Howard Hinnantb64f8b02010-11-16 22:09:02 +00005// This file is dual licensed under the MIT and the University of Illinois Open
6// Source Licenses. See LICENSE.TXT for details.
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00007//
8//===----------------------------------------------------------------------===//
9
10// <vector>
11
Marshall Clow127db912015-06-04 00:10:20 +000012// vector();
13// vector(const Alloc&);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000014
15#include <vector>
16#include <cassert>
17
Marshall Clowc912c0c2015-06-04 02:05:41 +000018#include "test_macros.h"
Marshall Clow1b921882013-12-03 00:18:10 +000019#include "test_allocator.h"
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000020#include "../../../NotConstructible.h"
21#include "../../../stack_allocator.h"
Marshall Clow061d0cc2013-11-26 20:58:02 +000022#include "min_allocator.h"
Marshall Clow1f50f2d2014-05-08 14:14:06 +000023#include "asan_testing.h"
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000024
25template <class C>
26void
27test0()
28{
Marshall Clow127db912015-06-04 00:10:20 +000029#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 Hinnantbc8d3f92010-05-11 19:42:16 +000034 C c;
Dan Albert1d4a1ed2016-05-25 22:36:09 -070035 assert(c.__invariants());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000036 assert(c.empty());
37 assert(c.get_allocator() == typename C::allocator_type());
Dan Albert1d4a1ed2016-05-25 22:36:09 -070038 assert(is_contiguous_container_asan_correct(c));
Marshall Clow127db912015-06-04 00:10:20 +000039#if TEST_STD_VER >= 11
Marshall Clow48c74702014-03-05 19:06:20 +000040 C c1 = {};
Dan Albert1d4a1ed2016-05-25 22:36:09 -070041 assert(c1.__invariants());
Marshall Clow48c74702014-03-05 19:06:20 +000042 assert(c1.empty());
43 assert(c1.get_allocator() == typename C::allocator_type());
Dan Albert1d4a1ed2016-05-25 22:36:09 -070044 assert(is_contiguous_container_asan_correct(c1));
Marshall Clow48c74702014-03-05 19:06:20 +000045#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000046}
47
48template <class C>
49void
50test1(const typename C::allocator_type& a)
51{
Marshall Clow127db912015-06-04 00:10:20 +000052#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 Hinnantbc8d3f92010-05-11 19:42:16 +000057 C c(a);
Dan Albert1d4a1ed2016-05-25 22:36:09 -070058 assert(c.__invariants());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000059 assert(c.empty());
60 assert(c.get_allocator() == a);
Dan Albert1d4a1ed2016-05-25 22:36:09 -070061 assert(is_contiguous_container_asan_correct(c));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000062}
63
64int 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 Clow127db912015-06-04 00:10:20 +000077#if TEST_STD_VER >= 11
Howard Hinnant2c39cbe2013-06-27 19:35:32 +000078 {
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 Hinnantbc8d3f92010-05-11 19:42:16 +000090}