15a83710eSEric Fiselier //===----------------------------------------------------------------------===//
25a83710eSEric Fiselier //
357b08b09SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
457b08b09SChandler Carruth // See https://llvm.org/LICENSE.txt for license information.
557b08b09SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
65a83710eSEric Fiselier //
75a83710eSEric Fiselier //===----------------------------------------------------------------------===//
85a83710eSEric Fiselier 
91f4231f8SEric Fiselier // UNSUPPORTED: c++98, c++03
101f4231f8SEric Fiselier 
115a83710eSEric Fiselier // <string>
125a83710eSEric Fiselier 
135a83710eSEric Fiselier // basic_string(basic_string&& str, const Allocator& alloc);
145a83710eSEric Fiselier 
155a83710eSEric Fiselier #include <string>
165a83710eSEric Fiselier #include <cassert>
175a83710eSEric Fiselier 
18cbf166a2SMarshall Clow #include "test_macros.h"
195a83710eSEric Fiselier #include "test_allocator.h"
205a83710eSEric Fiselier #include "min_allocator.h"
215a83710eSEric Fiselier 
225a83710eSEric Fiselier 
235a83710eSEric Fiselier template <class S>
245a83710eSEric Fiselier void
255a83710eSEric Fiselier test(S s0, const typename S::allocator_type& a)
265a83710eSEric Fiselier {
275a83710eSEric Fiselier     S s1 = s0;
285a83710eSEric Fiselier     S s2(std::move(s0), a);
291f4231f8SEric Fiselier     LIBCPP_ASSERT(s2.__invariants());
301f4231f8SEric Fiselier     LIBCPP_ASSERT(s0.__invariants());
315a83710eSEric Fiselier     assert(s2 == s1);
325a83710eSEric Fiselier     assert(s2.capacity() >= s2.size());
335a83710eSEric Fiselier     assert(s2.get_allocator() == a);
345a83710eSEric Fiselier }
355a83710eSEric Fiselier 
365a83710eSEric Fiselier 
37*2df59c50SJF Bastien int main(int, char**)
385a83710eSEric Fiselier {
395a83710eSEric Fiselier     {
405a83710eSEric Fiselier     typedef test_allocator<char> A;
415a83710eSEric Fiselier     typedef std::basic_string<char, std::char_traits<char>, A> S;
42cbf166a2SMarshall Clow #if TEST_STD_VER > 14
43cbf166a2SMarshall Clow     static_assert((noexcept(S{})), "" );
44cbf166a2SMarshall Clow #elif TEST_STD_VER >= 11
45cbf166a2SMarshall Clow     static_assert((noexcept(S()) == std::is_nothrow_move_constructible<A>::value), "" );
46cbf166a2SMarshall Clow #endif
475a83710eSEric Fiselier     test(S(), A(3));
485a83710eSEric Fiselier     test(S("1"), A(5));
495a83710eSEric Fiselier     test(S("1234567890123456789012345678901234567890123456789012345678901234567890"), A(7));
505a83710eSEric Fiselier     }
515a83710eSEric Fiselier 
525a83710eSEric Fiselier     int alloc_count = test_alloc_base::alloc_count;
535a83710eSEric Fiselier     {
545a83710eSEric Fiselier     typedef test_allocator<char> A;
555a83710eSEric Fiselier     typedef std::basic_string<char, std::char_traits<char>, A> S;
56cbf166a2SMarshall Clow #if TEST_STD_VER > 14
57cbf166a2SMarshall Clow     static_assert((noexcept(S{})), "" );
58cbf166a2SMarshall Clow #elif TEST_STD_VER >= 11
59cbf166a2SMarshall Clow     static_assert((noexcept(S()) == std::is_nothrow_move_constructible<A>::value), "" );
60cbf166a2SMarshall Clow #endif
615a83710eSEric Fiselier     S s1 ( "Twas brillig, and the slivy toves did gyre and gymbal in the wabe" );
625a83710eSEric Fiselier     S s2 (std::move(s1), A(1));
635a83710eSEric Fiselier     }
645a83710eSEric Fiselier     assert ( test_alloc_base::alloc_count == alloc_count );
655a83710eSEric Fiselier     {
665a83710eSEric Fiselier     typedef min_allocator<char> A;
675a83710eSEric Fiselier     typedef std::basic_string<char, std::char_traits<char>, A> S;
68cbf166a2SMarshall Clow #if TEST_STD_VER > 14
69cbf166a2SMarshall Clow     static_assert((noexcept(S{})), "" );
70cbf166a2SMarshall Clow #elif TEST_STD_VER >= 11
71cbf166a2SMarshall Clow     static_assert((noexcept(S()) == std::is_nothrow_move_constructible<A>::value), "" );
72cbf166a2SMarshall Clow #endif
735a83710eSEric Fiselier     test(S(), A());
745a83710eSEric Fiselier     test(S("1"), A());
755a83710eSEric Fiselier     test(S("1234567890123456789012345678901234567890123456789012345678901234567890"), A());
765a83710eSEric Fiselier     }
77*2df59c50SJF Bastien 
78*2df59c50SJF Bastien   return 0;
795a83710eSEric Fiselier }
80