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 // XFAIL: LIBCXX-AIX-FIXME 10 11 // <string> 12 13 // basic_string<charT,traits,Allocator>& 14 // append(const basic_string<charT,traits>& str); // constexpr since C++20 15 16 #include <string> 17 #include <cassert> 18 19 #include "test_macros.h" 20 #include "min_allocator.h" 21 22 template <class S> 23 TEST_CONSTEXPR_CXX20 void 24 test(S s, S str, S expected) 25 { 26 s.append(str); 27 LIBCPP_ASSERT(s.__invariants()); 28 assert(s == expected); 29 } 30 31 TEST_CONSTEXPR_CXX20 bool test() { 32 { 33 typedef std::string S; 34 test(S(), S(), S()); 35 test(S(), S("12345"), S("12345")); 36 test(S(), S("1234567890"), S("1234567890")); 37 test(S(), S("12345678901234567890"), S("12345678901234567890")); 38 39 test(S("12345"), S(), S("12345")); 40 test(S("12345"), S("12345"), S("1234512345")); 41 test(S("12345"), S("1234567890"), S("123451234567890")); 42 test(S("12345"), S("12345678901234567890"), S("1234512345678901234567890")); 43 44 test(S("1234567890"), S(), S("1234567890")); 45 test(S("1234567890"), S("12345"), S("123456789012345")); 46 test(S("1234567890"), S("1234567890"), S("12345678901234567890")); 47 test(S("1234567890"), S("12345678901234567890"), S("123456789012345678901234567890")); 48 49 test(S("12345678901234567890"), S(), S("12345678901234567890")); 50 test(S("12345678901234567890"), S("12345"), S("1234567890123456789012345")); 51 test(S("12345678901234567890"), S("1234567890"), S("123456789012345678901234567890")); 52 test(S("12345678901234567890"), S("12345678901234567890"), 53 S("1234567890123456789012345678901234567890")); 54 } 55 #if TEST_STD_VER >= 11 56 { 57 typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S; 58 test(S(), S(), S()); 59 test(S(), S("12345"), S("12345")); 60 test(S(), S("1234567890"), S("1234567890")); 61 test(S(), S("12345678901234567890"), S("12345678901234567890")); 62 63 test(S("12345"), S(), S("12345")); 64 test(S("12345"), S("12345"), S("1234512345")); 65 test(S("12345"), S("1234567890"), S("123451234567890")); 66 test(S("12345"), S("12345678901234567890"), S("1234512345678901234567890")); 67 68 test(S("1234567890"), S(), S("1234567890")); 69 test(S("1234567890"), S("12345"), S("123456789012345")); 70 test(S("1234567890"), S("1234567890"), S("12345678901234567890")); 71 test(S("1234567890"), S("12345678901234567890"), S("123456789012345678901234567890")); 72 73 test(S("12345678901234567890"), S(), S("12345678901234567890")); 74 test(S("12345678901234567890"), S("12345"), S("1234567890123456789012345")); 75 test(S("12345678901234567890"), S("1234567890"), S("123456789012345678901234567890")); 76 test(S("12345678901234567890"), S("12345678901234567890"), 77 S("1234567890123456789012345678901234567890")); 78 } 79 #endif 80 81 #if TEST_STD_VER > 3 82 { // LWG 2946 83 std::string s; 84 s.append({"abc", 1}); 85 assert(s.size() == 1); 86 assert(s == "a"); 87 } 88 #endif 89 90 return true; 91 } 92 93 int main(int, char**) 94 { 95 test(); 96 #if TEST_STD_VER > 17 97 static_assert(test()); 98 #endif 99 100 return 0; 101 } 102