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& operator=(initializer_list<charT> il); // constexpr since C++20
18 #include "test_macros.h"
19 #include "min_allocator.h"
20 #include "asan_testing.h"
23 template <template <class> class Alloc
>
24 TEST_CONSTEXPR_CXX20
void test_string() {
26 typedef std::basic_string
<char, std::char_traits
<char>, Alloc
<char>> S
;
28 S
& result
= (s
= {'a', 'b', 'c'});
30 assert(&result
== &s
);
31 LIBCPP_ASSERT(is_string_asan_correct(s
));
32 LIBCPP_ASSERT(is_string_asan_correct(result
));
35 typedef std::basic_string
<char, std::char_traits
<char>, Alloc
<char>> S
;
37 s
= {'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a',
38 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a'};
39 assert(s
== "aaaaaaaaaaaaaaaaaaaaaaaa");
40 LIBCPP_ASSERT(is_string_asan_correct(s
));
42 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
44 typedef std::basic_string
<wchar_t, std::char_traits
<wchar_t>, Alloc
<wchar_t>> S
;
46 S
& result
= (s
= {L
'a', L
'b', L
'c'});
48 assert(&result
== &s
);
49 LIBCPP_ASSERT(is_string_asan_correct(s
));
50 LIBCPP_ASSERT(is_string_asan_correct(result
));
53 typedef std::basic_string
<wchar_t, std::char_traits
<wchar_t>, Alloc
<wchar_t>> S
;
55 S
& result
= (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'});
56 assert(s
== L
"aaaaaaaaaaaaaaaaaaaaaaaaa");
57 assert(&result
== &s
);
58 LIBCPP_ASSERT(is_string_asan_correct(s
));
59 LIBCPP_ASSERT(is_string_asan_correct(result
));
65 TEST_CONSTEXPR_CXX20
bool test() {
66 test_string
<std::allocator
>();
67 test_string
<min_allocator
>();
68 test_string
<safe_allocator
>();
73 int main(int, char**) {
76 static_assert(test());