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& append(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 "nasty_string.h"
21 #include "asan_testing.h"
22
23 template <class S>
test()24 TEST_CONSTEXPR_CXX20 void test() {
25 using CharT = typename S::value_type;
26
27 S s(CONVERT_TO_CSTRING(CharT, "123"));
28 s.append({CharT('a'), CharT('b'), CharT('c')});
29 assert(s == CONVERT_TO_CSTRING(CharT, "123abc"));
30 LIBCPP_ASSERT(is_string_asan_correct(s));
31 }
32
test()33 TEST_CONSTEXPR_CXX20 bool test() {
34 test<std::string>();
35 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
36 test<std::wstring>();
37 #endif
38 #if TEST_STD_VER >= 20
39 test<std::u8string>();
40 #endif
41 test<std::u16string>();
42 test<std::u32string>();
43
44 test<std::basic_string<char, std::char_traits<char>, min_allocator<char>>>();
45 test<std::basic_string<char, std::char_traits<char>, safe_allocator<char>>>();
46 #ifndef TEST_HAS_NO_NASTY_STRING
47 test<nasty_string>();
48 #endif
49
50 return true;
51 }
52
main(int,char **)53 int main(int, char**) {
54 test();
55 #if TEST_STD_VER > 17
56 static_assert(test());
57 #endif
58
59 return 0;
60 }
61