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 //===----------------------------------------------------------------------===//
13 // basic_string(initializer_list<charT> il, const Allocator& a = Allocator()); // constexpr since C++20
18 #include "test_macros.h"
19 #include "test_allocator.h"
20 #include "min_allocator.h"
21 #include "asan_testing.h"
24 template <template <class> class Alloc
>
25 TEST_CONSTEXPR_CXX20
void test_string() {
27 std::basic_string
<char, std::char_traits
<char>, Alloc
<char> > s
= {'a', 'b', 'c'};
29 LIBCPP_ASSERT(is_string_asan_correct(s
));
32 std::basic_string
<char, std::char_traits
<char>, Alloc
<char> > s
= {'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a'};
33 assert(s
== "aaaaaaaaaaaaaaaaaaaaaaaaa");
34 LIBCPP_ASSERT(is_string_asan_correct(s
));
36 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
38 std::basic_string
<wchar_t, std::char_traits
<wchar_t>, Alloc
<wchar_t> > s
= {L
'a', L
'b', L
'c'};
40 LIBCPP_ASSERT(is_string_asan_correct(s
));
43 std::basic_string
<wchar_t, std::char_traits
<wchar_t>, Alloc
<wchar_t> > s
= {L
'a', L
'a', L
'a', L
'a', L
'a', L
'a', L
'a', L
'a', L
'a', L
'a', L
'a', L
'a', L
'a', L
'a', L
'a', L
'a', L
'a', L
'a', L
'a', L
'a', L
'a', L
'a', L
'a', L
'a', L
'a'};
44 assert(s
== L
"aaaaaaaaaaaaaaaaaaaaaaaaa");
45 LIBCPP_ASSERT(is_string_asan_correct(s
));
51 TEST_CONSTEXPR_CXX20
bool test() {
52 test_string
<std::allocator
>();
53 test_string
<min_allocator
>();
54 test_string
<safe_allocator
>();
59 int main(int, char**) {
62 static_assert(test());