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