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 // operator=(const basic_string<charT,traits,Allocator>& 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 s1, const S& s2) 25 { 26 s1 = s2; 27 LIBCPP_ASSERT(s1.__invariants()); 28 assert(s1 == s2); 29 assert(s1.capacity() >= s1.size()); 30 } 31 32 TEST_CONSTEXPR_CXX20 bool test() { 33 { 34 typedef std::string S; 35 test(S(), S()); 36 test(S("1"), S()); 37 test(S(), S("1")); 38 test(S("1"), S("2")); 39 test(S("1"), S("2")); 40 41 test(S(), 42 S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz")); 43 test(S("123456789"), 44 S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz")); 45 test(S("1234567890123456789012345678901234567890123456789012345678901234567890"), 46 S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz")); 47 test(S("1234567890123456789012345678901234567890123456789012345678901234567890" 48 "1234567890123456789012345678901234567890123456789012345678901234567890"), 49 S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz")); 50 } 51 #if TEST_STD_VER >= 11 52 { 53 typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S; 54 test(S(), S()); 55 test(S("1"), S()); 56 test(S(), S("1")); 57 test(S("1"), S("2")); 58 test(S("1"), S("2")); 59 60 test(S(), 61 S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz")); 62 test(S("123456789"), 63 S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz")); 64 test(S("1234567890123456789012345678901234567890123456789012345678901234567890"), 65 S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz")); 66 test(S("1234567890123456789012345678901234567890123456789012345678901234567890" 67 "1234567890123456789012345678901234567890123456789012345678901234567890"), 68 S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz")); 69 } 70 #endif 71 72 #if TEST_STD_VER > 3 73 { // LWG 2946 74 std::string s; 75 s = {"abc", 1}; 76 assert(s.size() == 1); 77 assert(s == "a"); 78 } 79 #endif 80 81 return true; 82 } 83 84 int main(int, char**) 85 { 86 test(); 87 #if TEST_STD_VER > 17 88 static_assert(test()); 89 #endif 90 91 return 0; 92 } 93