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// <vector>
10
11// vector();
12// vector(const Alloc&);
13
14#include <vector>
15#include <cassert>
16
17#include "test_macros.h"
18#include "test_allocator.h"
19#include "../../../NotConstructible.h"
20#include "test_allocator.h"
21#include "min_allocator.h"
22#include "asan_testing.h"
23
24template <class C>
25TEST_CONSTEXPR_CXX20 void test0()
26{
27#if TEST_STD_VER > 14
28 static_assert((noexcept(C{})), "" );
29#elif TEST_STD_VER >= 11
30 static_assert((noexcept(C()) == noexcept(typename C::allocator_type())), "" );
31#endif
32 C c;
33 LIBCPP_ASSERT(c.__invariants());
34 assert(c.empty());
35 assert(c.get_allocator() == typename C::allocator_type());
36 LIBCPP_ASSERT(is_contiguous_container_asan_correct(c));
37#if TEST_STD_VER >= 11
38 C c1 = {};
39 LIBCPP_ASSERT(c1.__invariants());
40 assert(c1.empty());
41 assert(c1.get_allocator() == typename C::allocator_type());
42 LIBCPP_ASSERT(is_contiguous_container_asan_correct(c1));
43#endif
44}
45
46template <class C>
47TEST_CONSTEXPR_CXX20 void test1(const typename C::allocator_type& a)
48{
49#if TEST_STD_VER > 14
50 static_assert((noexcept(C{typename C::allocator_type{}})), "" );
51#elif TEST_STD_VER >= 11
52 static_assert((noexcept(C(typename C::allocator_type())) == std::is_nothrow_copy_constructible<typename C::allocator_type>::value), "" );
53#endif
54 C c(a);
55 LIBCPP_ASSERT(c.__invariants());
56 assert(c.empty());
57 assert(c.get_allocator() == a);
58 LIBCPP_ASSERT(is_contiguous_container_asan_correct(c));
59}
60
61TEST_CONSTEXPR_CXX20 bool tests() {
62 {
63 test0<std::vector<int> >();
64 test0<std::vector<NotConstructible> >();
65 test1<std::vector<int, test_allocator<int> > >(test_allocator<int>(3));
66 test1<std::vector<NotConstructible, test_allocator<NotConstructible> > >
67 (test_allocator<NotConstructible>(5));
68 }
69 {
70 std::vector<int, limited_allocator<int, 10> > v;
71 assert(v.empty());
72 }
73#if TEST_STD_VER >= 11
74 {
75 test0<std::vector<int, min_allocator<int>> >();
76 test0<std::vector<NotConstructible, min_allocator<NotConstructible>> >();
77 test1<std::vector<int, min_allocator<int> > >(min_allocator<int>{});
78 test1<std::vector<NotConstructible, min_allocator<NotConstructible> > >
79 (min_allocator<NotConstructible>{});
80 }
81 {
82 std::vector<int, min_allocator<int> > v;
83 assert(v.empty());
84 }
85
86 {
87 test0<std::vector<int, explicit_allocator<int>> >();
88 test0<std::vector<NotConstructible, explicit_allocator<NotConstructible>> >();
89 test1<std::vector<int, explicit_allocator<int> > >(explicit_allocator<int>{});
90 test1<std::vector<NotConstructible, explicit_allocator<NotConstructible> > >
91 (explicit_allocator<NotConstructible>{});
92 }
93 {
94 std::vector<int, explicit_allocator<int> > v;
95 assert(v.empty());
96 }
97#endif
98
99 return true;
100}
101
102int main(int, char**)
103{
104 tests();
105#if TEST_STD_VER > 17
106 static_assert(tests());
107#endif
108 return 0;
109}
110

source code of libcxx/test/std/containers/sequences/vector/vector.cons/construct_default.pass.cpp