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 // UNSUPPORTED: c++03
10
11 // <string>
12
13 // basic_string& assign(initializer_list<charT> il); // constexpr since C++20
14
15 #include <string>
16 #include <cassert>
17
18 #include "test_macros.h"
19 #include "min_allocator.h"
20 #include "asan_testing.h"
21
22 template <class S>
test_string()23 TEST_CONSTEXPR_CXX20 void test_string() {
24 S s("123");
25
26 s.assign({'a', 'b'});
27 assert(s == "ab");
28 LIBCPP_ASSERT(is_string_asan_correct(s));
29
30 s.assign({'a', 'b', 'c'});
31 assert(s == "abc");
32 LIBCPP_ASSERT(is_string_asan_correct(s));
33
34 s.assign({'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a',
35 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a'});
36 assert(s == "aaaaaaaaaaaaaaaaaaaaaaaaa");
37 LIBCPP_ASSERT(is_string_asan_correct(s));
38 }
39
test()40 TEST_CONSTEXPR_CXX20 bool test() {
41 test_string<std::string>();
42 #if TEST_STD_VER >= 11
43 test_string<std::basic_string<char, std::char_traits<char>, min_allocator<char> > >();
44 test_string<std::basic_string<char, std::char_traits<char>, safe_allocator<char> > >();
45 #endif
46
47 return true;
48 }
49
main(int,char **)50 int main(int, char**) {
51 test();
52 #if TEST_STD_VER > 17
53 static_assert(test());
54 #endif
55
56 return 0;
57 }
58