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"
19 #include "asan_testing.h"
22 TEST_CONSTEXPR_CXX20
void test() {
25 static_assert((noexcept(S
{})), "");
26 #elif TEST_STD_VER >= 11
27 static_assert((noexcept(S()) == noexcept(typename
S::allocator_type())), "");
30 LIBCPP_ASSERT(s
.__invariants());
32 assert(s
.size() == 0);
33 assert(s
.capacity() >= s
.size());
34 assert(s
.get_allocator() == typename
S::allocator_type());
35 LIBCPP_ASSERT(is_string_asan_correct(s
));
39 static_assert((noexcept(S
{typename
S::allocator_type
{}})), "");
40 #elif TEST_STD_VER >= 11
41 static_assert((noexcept(S(typename
S::allocator_type())) ==
42 std::is_nothrow_copy_constructible
<typename
S::allocator_type
>::value
),
45 S
s(typename
S::allocator_type(5));
46 LIBCPP_ASSERT(s
.__invariants());
48 assert(s
.size() == 0);
49 assert(s
.capacity() >= s
.size());
50 assert(s
.get_allocator() == typename
S::allocator_type(5));
51 LIBCPP_ASSERT(is_string_asan_correct(s
));
55 #if TEST_STD_VER >= 11
58 TEST_CONSTEXPR_CXX20
void test2() {
60 # if TEST_STD_VER > 14
61 static_assert((noexcept(S
{})), "");
62 # elif TEST_STD_VER >= 11
63 static_assert((noexcept(S()) == noexcept(typename
S::allocator_type())), "");
66 LIBCPP_ASSERT(s
.__invariants());
68 assert(s
.size() == 0);
69 assert(s
.capacity() >= s
.size());
70 assert(s
.get_allocator() == typename
S::allocator_type());
71 LIBCPP_ASSERT(is_string_asan_correct(s
));
74 # if TEST_STD_VER > 14
75 static_assert((noexcept(S
{typename
S::allocator_type
{}})), "");
76 # elif TEST_STD_VER >= 11
77 static_assert((noexcept(S(typename
S::allocator_type())) ==
78 std::is_nothrow_copy_constructible
<typename
S::allocator_type
>::value
),
81 S
s(typename
S::allocator_type
{});
82 LIBCPP_ASSERT(s
.__invariants());
84 assert(s
.size() == 0);
85 assert(s
.capacity() >= s
.size());
86 assert(s
.get_allocator() == typename
S::allocator_type());
87 LIBCPP_ASSERT(is_string_asan_correct(s
));
93 TEST_CONSTEXPR_CXX20
bool test() {
94 test
<std::basic_string
<char, std::char_traits
<char>, test_allocator
<char> > >();
95 #if TEST_STD_VER >= 11
96 test2
<std::basic_string
<char, std::char_traits
<char>, min_allocator
<char> > >();
97 test2
<std::basic_string
<char, std::char_traits
<char>, safe_allocator
<char> > >();
98 test2
<std::basic_string
<char, std::char_traits
<char>, explicit_allocator
<char> > >();
104 int main(int, char**) {
106 #if TEST_STD_VER > 17
107 static_assert(test());