Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libcxx / test / std / strings / basic.string / string.cons / move.pass.cpp
blobf5ffebd35d50e92d86ed14645122a3af4a7eb3bb
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 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: c++03
11 // <string>
13 // basic_string(basic_string<charT,traits,Allocator>&& str); // constexpr since C++20
15 #include <string>
16 #include <cassert>
18 #include "test_macros.h"
19 #include "test_allocator.h"
20 #include "min_allocator.h"
22 template <class S>
23 TEST_CONSTEXPR_CXX20 void test(S s0) {
24 S s1 = s0;
25 S s2 = std::move(s0);
26 LIBCPP_ASSERT(s2.__invariants());
27 LIBCPP_ASSERT(s0.__invariants());
28 assert(s2 == s1);
29 assert(s2.capacity() >= s2.size());
30 assert(s2.get_allocator() == s1.get_allocator());
33 template <class Alloc>
34 TEST_CONSTEXPR_CXX20 void test_string(Alloc const& a) {
35 using S = std::basic_string<char, std::char_traits<char>, Alloc>;
36 test(S(Alloc(a)));
37 test(S("1", Alloc(a)));
38 test(S("1234567890123456789012345678901234567890123456789012345678901234567890", Alloc(a)));
41 TEST_CONSTEXPR_CXX20 bool test() {
42 test_string(std::allocator<char>());
43 test_string(test_allocator<char>());
44 test_string(test_allocator<char>(3));
45 test_string(min_allocator<char>());
47 return true;
50 int main(int, char**) {
51 test();
52 #if TEST_STD_VER > 17
53 static_assert(test());
54 #endif
56 return 0;