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(basic_string<charT,traits,Allocator>&& str); // constexpr since C++20
14 
15 #include <string>
16 #include <cassert>
17 
18 #include "test_macros.h"
19 #include "test_allocator.h"
20 #include "min_allocator.h"
21 
22 template <class S>
23 TEST_CONSTEXPR_CXX20 void
24 test(S s0)
25 {
26     S s1 = s0;
27     S s2 = std::move(s0);
28     LIBCPP_ASSERT(s2.__invariants());
29     LIBCPP_ASSERT(s0.__invariants());
30     assert(s2 == s1);
31     assert(s2.capacity() >= s2.size());
32     assert(s2.get_allocator() == s1.get_allocator());
33 }
34 
35 TEST_CONSTEXPR_CXX20 bool test() {
36   {
37     typedef test_allocator<char> A;
38     typedef std::basic_string<char, std::char_traits<char>, A> S;
39     test(S(A(3)));
40     test(S("1", A(5)));
41     test(S("1234567890123456789012345678901234567890123456789012345678901234567890", A(7)));
42   }
43   {
44     typedef min_allocator<char> A;
45     typedef std::basic_string<char, std::char_traits<char>, A> S;
46     test(S(A{}));
47     test(S("1", A()));
48     test(S("1234567890123456789012345678901234567890123456789012345678901234567890", A()));
49   }
50 
51   return true;
52 }
53 
54 int main(int, char**)
55 {
56   test();
57 #if TEST_STD_VER > 17
58   static_assert(test());
59 #endif
60 
61   return 0;
62 }
63