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

source code of libcxx/test/std/strings/basic.string/string.cons/copy.pass.cpp