]>
Commit | Line | Data |
---|---|---|
8d9254fc | 1 | // Copyright (C) 2017-2020 Free Software Foundation, Inc. |
6d82c562 JW |
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" } | |
7b936140 | 19 | // { dg-do compile { target c++17 } } |
339657d2 | 20 | // { dg-xfail-if "COW string missing deduction guides" { ! cxx11-abi } } |
6d82c562 JW |
21 | |
22 | #include <string> | |
23 | #include <testsuite_iterators.h> | |
24 | ||
25 | template<typename C> | |
26 | using input_iterator_seq | |
27 | = __gnu_test::test_container<C, __gnu_test::input_iterator_wrapper>; | |
28 | ||
29 | template<typename T, typename U> struct require_same; | |
30 | template<typename T> struct require_same<T, T> { using type = void; }; | |
31 | ||
32 | template<typename T, typename U> | |
33 | typename require_same<T, U>::type | |
34 | check_type(U&) { } | |
35 | ||
36 | void | |
37 | test01() | |
38 | { | |
39 | std::string s0; | |
40 | std::allocator<char> a; | |
41 | ||
42 | std::basic_string s1 = s0; | |
43 | check_type<std::string>(s1); | |
44 | ||
45 | std::basic_string s2 = std::move(s0); | |
46 | check_type<std::string>(s2); | |
47 | ||
48 | const std::basic_string s3 = s0; | |
49 | check_type<const std::string>(s3); | |
50 | ||
51 | const std::basic_string s4 = s3; | |
52 | check_type<const std::string>(s4); | |
53 | ||
cdd17d6e | 54 | #if _GLIBCXX_USE_CXX11_ABI |
6d82c562 JW |
55 | std::basic_string s5(s0, a); |
56 | check_type<std::string>(s5); | |
57 | ||
58 | std::basic_string s6(std::move(s0), a); | |
59 | check_type<std::string>(s6); | |
cdd17d6e | 60 | #endif |
6d82c562 JW |
61 | |
62 | std::basic_string s7(s0, 0, 0); | |
63 | check_type<std::string>(s7); | |
64 | } | |
65 | ||
66 | void | |
67 | test02() | |
68 | { | |
69 | char a[1] = {}; | |
70 | input_iterator_seq<char> seq(a); | |
71 | ||
72 | std::basic_string s1(seq.begin(), seq.end()); | |
73 | check_type<std::string>(s1); | |
74 | ||
75 | std::basic_string s2(seq.begin(), seq.end(), std::allocator<char>()); | |
76 | check_type<std::string>(s2); | |
77 | ||
78 | std::basic_string s3((char)1, 'a'); | |
79 | check_type<std::string>(s3); | |
80 | ||
81 | std::basic_string s4((char)1, 'a', std::allocator<char>()); | |
82 | check_type<std::string>(s4); | |
83 | } | |
84 | ||
85 | void | |
86 | test03() | |
87 | { | |
88 | char16_t a[1] = {}; | |
89 | input_iterator_seq<char16_t> seq(a); | |
90 | ||
91 | std::basic_string s1(seq.begin(), seq.end()); | |
92 | check_type<std::u16string>(s1); | |
93 | ||
94 | std::basic_string s2(seq.begin(), seq.end(), std::allocator<char16_t>()); | |
95 | check_type<std::u16string>(s2); | |
96 | ||
97 | std::basic_string s3((char16_t)1, u'a'); | |
98 | check_type<std::u16string>(s3); | |
99 | ||
100 | std::basic_string s4((char16_t)1, u'a', std::allocator<char16_t>()); | |
101 | check_type<std::u16string>(s4); | |
102 | } | |
103 | ||
104 | void | |
105 | test04() | |
106 | { | |
107 | char32_t a[1] = {}; | |
108 | input_iterator_seq<char32_t> seq(a); | |
109 | ||
110 | std::basic_string s1(seq.begin(), seq.end()); | |
111 | check_type<std::u32string>(s1); | |
112 | ||
113 | std::basic_string s2(seq.begin(), seq.end(), std::allocator<char32_t>()); | |
114 | check_type<std::u32string>(s2); | |
115 | ||
116 | std::basic_string s3((char32_t)1, U'a'); | |
117 | check_type<std::u32string>(s3); | |
118 | ||
119 | std::basic_string s4((char32_t)1, U'a', std::allocator<char32_t>()); | |
120 | check_type<std::u32string>(s4); | |
121 | } | |
53e926c8 JW |
122 | |
123 | void | |
124 | test05() | |
59019b42 TH |
125 | { |
126 | #ifdef _GLIBCXX_USE_CHAR8_T | |
127 | char8_t a[1] = {}; | |
128 | input_iterator_seq<char8_t> seq(a); | |
129 | ||
130 | std::basic_string s1(seq.begin(), seq.end()); | |
131 | check_type<std::u8string>(s1); | |
132 | ||
133 | std::basic_string s2(seq.begin(), seq.end(), std::allocator<char8_t>()); | |
134 | check_type<std::u8string>(s2); | |
135 | ||
136 | std::basic_string s3((char8_t)1, u8'a'); | |
137 | check_type<std::u8string>(s3); | |
138 | ||
139 | std::basic_string s4((char8_t)1, u8'a', std::allocator<char8_t>()); | |
140 | check_type<std::u8string>(s4); | |
141 | #endif | |
142 | } | |
143 | ||
144 | void | |
145 | test06() | |
53e926c8 JW |
146 | { |
147 | // LWG 3075 basic_string needs deduction guides from basic_string_view | |
148 | std::string_view sv{"A View to a Kill"}; | |
149 | const std::allocator<char> a; | |
150 | ||
151 | std::basic_string s1(sv); | |
152 | check_type<std::string>(s1); | |
153 | ||
154 | std::basic_string s2(sv, a); | |
155 | check_type<std::string>(s2); | |
156 | ||
157 | std::basic_string s3(sv, 2u, 6u); | |
158 | check_type<std::string>(s3); | |
159 | ||
160 | std::basic_string s4(sv, 2u, 6u, a); | |
161 | check_type<std::string>(s4); | |
162 | } | |
5d84e6c5 JW |
163 | |
164 | void | |
59019b42 | 165 | test07() |
5d84e6c5 JW |
166 | { |
167 | // LWG 3076 basic_string CTAD ambiguity | |
168 | using namespace std; | |
169 | string s0; | |
170 | ||
171 | basic_string s1(s0, 1, 1); | |
172 | check_type<std::string>(s1); | |
173 | ||
174 | basic_string s2("cat"sv, 1, 1); | |
175 | check_type<std::string>(s2); | |
176 | ||
177 | basic_string s3("cat", 1); | |
178 | check_type<std::string>(s3); | |
179 | } |