]>
Commit | Line | Data |
---|---|---|
fbd26352 | 1 | // Copyright (C) 2017-2019 Free Software Foundation, Inc. |
c2b91adc | 2 | // |
3 | // This file is part of the GNU ISO C++ Library. This library is free | |
4 | // software; you can redistribute it and/or modify it under the | |
5 | // terms of the GNU General Public License as published by the | |
6 | // Free Software Foundation; either version 3, or (at your option) | |
7 | // any later version. | |
8 | ||
9 | // This library is distributed in the hope that it will be useful, | |
10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | // GNU General Public License for more details. | |
13 | ||
14 | // You should have received a copy of the GNU General Public License along | |
15 | // with this library; see the file COPYING3. If not see | |
16 | // <http://www.gnu.org/licenses/>. | |
17 | ||
18 | // { dg-options "-std=gnu++17" } | |
40e2decb | 19 | // { dg-do compile { target c++17 } } |
46deba94 | 20 | // { dg-xfail-if "COW string missing deduction guides" { ! cxx11-abi } } |
c2b91adc | 21 | |
22 | #include <string> | |
23 | #include <testsuite_iterators.h> | |
24 | ||
25 | template<typename T, typename U> struct require_same; | |
26 | template<typename T> struct require_same<T, T> { using type = void; }; | |
27 | ||
28 | template<typename T, typename U> | |
29 | typename require_same<T, U>::type | |
30 | check_type(U&) { } | |
31 | ||
32 | void | |
33 | test01() | |
34 | { | |
35 | std::wstring s0; | |
36 | std::allocator<wchar_t> a; | |
37 | ||
38 | std::basic_string s1 = s0; | |
39 | check_type<std::wstring>(s1); | |
40 | ||
41 | std::basic_string s2 = std::move(s0); | |
42 | check_type<std::wstring>(s2); | |
43 | ||
44 | const std::basic_string s3 = s0; | |
45 | check_type<const std::wstring>(s3); | |
46 | ||
47 | const std::basic_string s4 = s2; | |
48 | check_type<const std::wstring>(s4); | |
49 | ||
38c23f01 | 50 | #if _GLIBCXX_USE_CXX11_ABI |
c2b91adc | 51 | std::basic_string s5(s0, a); |
52 | check_type<std::wstring>(s5); | |
53 | ||
54 | std::basic_string s6(std::move(s0), a); | |
55 | check_type<std::wstring>(s6); | |
38c23f01 | 56 | #endif |
c2b91adc | 57 | |
58 | std::basic_string s7(s0, 0, 0); | |
59 | check_type<std::wstring>(s7); | |
60 | } | |
61 | ||
62 | void | |
63 | test02() | |
64 | { | |
65 | using namespace __gnu_test; | |
66 | wchar_t a[1] = {}; | |
67 | test_container<wchar_t, input_iterator_wrapper> seq(a); | |
68 | ||
69 | std::basic_string s1(seq.begin(), seq.end()); | |
70 | check_type<std::wstring>(s1); | |
71 | ||
72 | std::basic_string s2(seq.begin(), seq.end(), std::allocator<wchar_t>()); | |
73 | check_type<std::wstring>(s2); | |
74 | ||
75 | std::basic_string s3((wchar_t)1, L'a'); | |
76 | check_type<std::wstring>(s3); | |
77 | ||
78 | std::basic_string s4((wchar_t)1, L'a', std::allocator<wchar_t>()); | |
79 | check_type<std::wstring>(s4); | |
80 | } | |
96a68164 | 81 | |
82 | void | |
83 | test05() | |
84 | { | |
85 | // LWG 3075 basic_string needs deduction guides from basic_string_view | |
86 | std::wstring_view sv{L"A View to a Kill"}; | |
87 | const std::allocator<wchar_t> a; | |
88 | ||
89 | std::basic_string s1(sv); | |
90 | check_type<std::wstring>(s1); | |
91 | ||
92 | std::basic_string s2(sv, a); | |
93 | check_type<std::wstring>(s2); | |
94 | ||
95 | std::basic_string s3(sv, 2u, 6u); | |
96 | check_type<std::wstring>(s3); | |
97 | ||
98 | std::basic_string s4(sv, 2u, 6u, a); | |
99 | check_type<std::wstring>(s4); | |
100 | } | |
95ca8aca | 101 | |
102 | void | |
103 | test06() | |
104 | { | |
105 | // LWG 3076 basic_string CTAD ambiguity | |
106 | using namespace std; | |
107 | wstring s0; | |
108 | ||
109 | basic_string s1(s0, 1, 1); | |
110 | check_type<std::wstring>(s1); | |
111 | ||
112 | basic_string s2(L"cat"sv, 1, 1); | |
113 | check_type<std::wstring>(s2); | |
114 | ||
115 | basic_string s3(L"cat", 1); | |
116 | check_type<std::wstring>(s3); | |
117 | } |