1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
11 // explicit basic_string(const Allocator& a = Allocator()); // constexpr since C++20
16 #include "test_macros.h"
17 #include "test_allocator.h"
18 #include "min_allocator.h"
21 TEST_CONSTEXPR_CXX20
void test() {
24 static_assert((noexcept(S
{})), "");
25 #elif TEST_STD_VER >= 11
26 static_assert((noexcept(S()) == noexcept(typename
S::allocator_type())), "");
29 LIBCPP_ASSERT(s
.__invariants());
31 assert(s
.size() == 0);
32 assert(s
.capacity() >= s
.size());
33 assert(s
.get_allocator() == typename
S::allocator_type());
37 static_assert((noexcept(S
{typename
S::allocator_type
{}})), "");
38 #elif TEST_STD_VER >= 11
39 static_assert((noexcept(S(typename
S::allocator_type())) ==
40 std::is_nothrow_copy_constructible
<typename
S::allocator_type
>::value
),
43 S
s(typename
S::allocator_type(5));
44 LIBCPP_ASSERT(s
.__invariants());
46 assert(s
.size() == 0);
47 assert(s
.capacity() >= s
.size());
48 assert(s
.get_allocator() == typename
S::allocator_type(5));
52 #if TEST_STD_VER >= 11
55 TEST_CONSTEXPR_CXX20
void test2() {
57 # if TEST_STD_VER > 14
58 static_assert((noexcept(S
{})), "");
59 # elif TEST_STD_VER >= 11
60 static_assert((noexcept(S()) == noexcept(typename
S::allocator_type())), "");
63 LIBCPP_ASSERT(s
.__invariants());
65 assert(s
.size() == 0);
66 assert(s
.capacity() >= s
.size());
67 assert(s
.get_allocator() == typename
S::allocator_type());
70 # if TEST_STD_VER > 14
71 static_assert((noexcept(S
{typename
S::allocator_type
{}})), "");
72 # elif TEST_STD_VER >= 11
73 static_assert((noexcept(S(typename
S::allocator_type())) ==
74 std::is_nothrow_copy_constructible
<typename
S::allocator_type
>::value
),
77 S
s(typename
S::allocator_type
{});
78 LIBCPP_ASSERT(s
.__invariants());
80 assert(s
.size() == 0);
81 assert(s
.capacity() >= s
.size());
82 assert(s
.get_allocator() == typename
S::allocator_type());
88 TEST_CONSTEXPR_CXX20
bool test() {
89 test
<std::basic_string
<char, std::char_traits
<char>, test_allocator
<char> > >();
90 #if TEST_STD_VER >= 11
91 test2
<std::basic_string
<char, std::char_traits
<char>, min_allocator
<char> > >();
92 test2
<std::basic_string
<char, std::char_traits
<char>, explicit_allocator
<char> > >();
98 int main(int, char**) {
100 #if TEST_STD_VER > 17
101 static_assert(test());