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