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#if TEST_STD_VER > 14
27 static_assert((noexcept(C{})), "");
28#elif TEST_STD_VER >= 11
29 static_assert((noexcept(C()) == noexcept(typename C::allocator_type())), "");
30#endif
31 C c;
32 LIBCPP_ASSERT(c.__invariants());
33 assert(c.empty());
34 assert(c.get_allocator() == typename C::allocator_type());
35 LIBCPP_ASSERT(is_contiguous_container_asan_correct(c));
36#if TEST_STD_VER >= 11
37 C c1 = {};
38 LIBCPP_ASSERT(c1.__invariants());
39 assert(c1.empty());
40 assert(c1.get_allocator() == typename C::allocator_type());
41 LIBCPP_ASSERT(is_contiguous_container_asan_correct(c1));
42#endif
43}
44
45template <class C>
46TEST_CONSTEXPR_CXX20 void test1(const typename C::allocator_type& a) {
47#if TEST_STD_VER > 14
48 static_assert((noexcept(C{typename C::allocator_type{}})), "");
49#elif TEST_STD_VER >= 11
50 static_assert((noexcept(C(typename C::allocator_type())) ==
51 std::is_nothrow_copy_constructible<typename C::allocator_type>::value),
52 "");
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> > >(test_allocator<NotConstructible>(5));
67 }
68 {
69 std::vector<int, limited_allocator<int, 10> > v;
70 assert(v.empty());
71 }
72#if TEST_STD_VER >= 11
73 {
74 test0<std::vector<int, min_allocator<int>> >();
75 test0<std::vector<NotConstructible, min_allocator<NotConstructible>> >();
76 test1<std::vector<int, min_allocator<int> > >(min_allocator<int>{});
77 test1<std::vector<NotConstructible, min_allocator<NotConstructible> > >(min_allocator<NotConstructible>{});
78 }
79 {
80 std::vector<int, min_allocator<int> > v;
81 assert(v.empty());
82 }
83
84 {
85 test0<std::vector<int, explicit_allocator<int>> >();
86 test0<std::vector<NotConstructible, explicit_allocator<NotConstructible>> >();
87 test1<std::vector<int, explicit_allocator<int> > >(explicit_allocator<int>{});
88 test1<std::vector<NotConstructible, explicit_allocator<NotConstructible> > >(
89 explicit_allocator<NotConstructible>{});
90 }
91 {
92 std::vector<int, explicit_allocator<int> > v;
93 assert(v.empty());
94 }
95#endif
96
97 return true;
98}
99
100int main(int, char**) {
101 tests();
102#if TEST_STD_VER > 17
103 static_assert(tests());
104#endif
105 return 0;
106}
107

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