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 // XFAIL: LIBCXX-AIX-FIXME 12 13 // <string> 14 15 // basic_string<charT,traits,Allocator>& 16 // operator=(basic_string<charT,traits,Allocator>&& str); // constexpr since C++20 17 18 #include <string> 19 #include <cassert> 20 21 #include "test_macros.h" 22 #include "test_allocator.h" 23 #include "min_allocator.h" 24 25 template <class S> 26 TEST_CONSTEXPR_CXX20 void 27 test(S s1, S s2) 28 { 29 S s0 = s2; 30 s1 = std::move(s2); 31 LIBCPP_ASSERT(s1.__invariants()); 32 LIBCPP_ASSERT(s2.__invariants()); 33 assert(s1 == s0); 34 assert(s1.capacity() >= s1.size()); 35 } 36 37 TEST_CONSTEXPR_CXX20 bool test() { 38 { 39 typedef std::string S; 40 test(S(), S()); 41 test(S("1"), S()); 42 test(S(), S("1")); 43 test(S("1"), S("2")); 44 test(S("1"), S("2")); 45 46 test(S(), 47 S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz")); 48 test(S("123456789"), 49 S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz")); 50 test(S("1234567890123456789012345678901234567890123456789012345678901234567890"), 51 S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz")); 52 test(S("1234567890123456789012345678901234567890123456789012345678901234567890" 53 "1234567890123456789012345678901234567890123456789012345678901234567890"), 54 S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz")); 55 } 56 { 57 typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S; 58 test(S(), S()); 59 test(S("1"), S()); 60 test(S(), S("1")); 61 test(S("1"), S("2")); 62 test(S("1"), S("2")); 63 64 test(S(), 65 S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz")); 66 test(S("123456789"), 67 S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz")); 68 test(S("1234567890123456789012345678901234567890123456789012345678901234567890"), 69 S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz")); 70 test(S("1234567890123456789012345678901234567890123456789012345678901234567890" 71 "1234567890123456789012345678901234567890123456789012345678901234567890"), 72 S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz")); 73 } 74 75 return true; 76 } 77 78 int main(int, char**) 79 { 80 test(); 81 #if TEST_STD_VER > 17 82 static_assert(test()); 83 #endif 84 85 return 0; 86 } 87