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