]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/20_util/tuple/cons/explicit_construct.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 20_util / tuple / cons / explicit_construct.cc
1 // { dg-do compile { target c++11 } }
2 // FIXME [!HOSTED]: avoidable std::allocator usage
3 // { dg-require-effective-target hosted }
4
5 // Copyright (C) 2015-2023 Free Software Foundation, Inc.
6 //
7 // This file is part of the GNU ISO C++ Library. This library is free
8 // software; you can redistribute it and/or modify it under the
9 // terms of the GNU General Public License as published by the
10 // Free Software Foundation; either version 3, or (at your option)
11 // any later version.
12 //
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
17 //
18 // You should have received a copy of the GNU General Public License along
19 // with this library; see the file COPYING3. If not see
20 // <http://www.gnu.org/licenses/>.
21
22
23 #include <tuple>
24 #include <utility>
25 #include <memory>
26
27 struct Explicit
28 {
29 Explicit() = default;
30 explicit Explicit(int) {}
31 };
32
33 struct ExplicitDefault
34 {
35 explicit ExplicitDefault() {}
36 };
37
38 struct ExplicitDefaultDefault
39 {
40 explicit ExplicitDefaultDefault() = default;
41 };
42
43 std::tuple<int> f1a() {return {1};}
44 std::tuple<int, int> f1b() {return {1,2};}
45 std::tuple<int, int, int> f1c() {return {1,2,3};}
46
47 std::tuple<Explicit> f2_a()
48 {return {1};} // { dg-error "could not convert" }
49 std::tuple<Explicit, Explicit> f2_b()
50 {return {1,2};} // { dg-error "could not convert" }
51 std::tuple<Explicit, Explicit, Explicit> f2_c()
52 {return {1,2,3};} // { dg-error "could not convert" }
53
54 std::tuple<long> f3_a() {return std::tuple<int>{1};}
55 std::tuple<long, long> f3_b() {return std::tuple<int, int>{1,2};}
56 std::tuple<long, long, long> f3_c() {return std::tuple<int, int, int>{1,2,3};}
57
58 std::tuple<Explicit> f4_a()
59 {
60 return std::tuple<int>{1}; // { dg-error "could not convert" }
61 }
62 std::tuple<Explicit, Explicit> f4_b()
63 {
64 return std::tuple<int, int>{1,2}; // { dg-error "could not convert" }
65 }
66 std::tuple<Explicit, Explicit, Explicit> f4_c()
67 {
68 return std::tuple<int, int,int>{1,2,3}; // { dg-error "could not convert" }
69 }
70
71 std::tuple<long> f5_a() {return {1};}
72 std::tuple<long, long> f5_b() {return {1,2};}
73 std::tuple<long, long, long> f5_c() {return {1,2,3};}
74
75 std::tuple<ExplicitDefault> f6_a()
76 {return {};} // { dg-error "could not convert" }
77 std::tuple<ExplicitDefault, ExplicitDefault> f6_b()
78 {return {};} // { dg-error "could not convert" }
79 std::tuple<ExplicitDefault, ExplicitDefault, ExplicitDefault> f6_c()
80 {return {};} // { dg-error "could not convert" }
81 std::tuple<ExplicitDefault, int> f6_d()
82 {return {};} // { dg-error "could not convert" }
83
84 std::tuple<ExplicitDefaultDefault> f7_a()
85 {return {};} // { dg-error "could not convert" }
86 std::tuple<ExplicitDefaultDefault, ExplicitDefaultDefault> f7_b()
87 {return {};} // { dg-error "could not convert" }
88 std::tuple<ExplicitDefaultDefault,
89 ExplicitDefaultDefault,
90 ExplicitDefaultDefault> f7_c()
91 {return {};} // { dg-error "could not convert" }
92
93 std::tuple<int, int> fp1() {return std::pair<int, int>{1,2}; }
94 std::tuple<long, long> fp2() {return std::pair<int, int>{1,2}; }
95 std::tuple<Explicit, Explicit> fp3()
96 {return std::pair<int, int>{1,2}; } // { dg-error "could not convert" }
97
98 std::tuple<int> v0_a{1};
99 std::tuple<int, int> v0_b{1,2};
100 std::tuple<int, int, int> v0_c{1,2,3};
101
102 std::tuple<Explicit> v1_a{1};
103 std::tuple<Explicit, Explicit> v1_b{1,2};
104 std::tuple<Explicit, Explicit, Explicit> v1_c{1,2,3};
105
106 std::tuple<Explicit> v2_a = {1}; // { dg-error "could not convert" }
107 std::tuple<Explicit, Explicit> v2_b = {1,2}; // { dg-error "could not convert" }
108 std::tuple<Explicit, Explicit, Explicit> v2_c = {1,2,3}; // { dg-error "could not convert" }
109
110 std::tuple<Explicit> v3_a{std::tuple<int>{1}};
111 std::tuple<Explicit, Explicit> v3_b{std::tuple<int,int>{1,2}};
112 std::tuple<Explicit, Explicit, Explicit> v3_c{std::tuple<int,int,int>{1,2,3}};
113
114 std::tuple<Explicit, Explicit> v4_a =
115 std::tuple<int>{1}; // { dg-error "conversion" }
116 std::tuple<Explicit, Explicit> v4_b =
117 std::tuple<int,int>{1,2}; // { dg-error "conversion" }
118 std::tuple<Explicit, Explicit, Explicit> v4_c =
119 std::tuple<int,int,int>{1,2,3}; // { dg-error "conversion" }
120
121 std::tuple<long> v6_a{1};
122 std::tuple<long, long> v6_b{1,2};
123 std::tuple<long, long, long> v6_c{1,2,3};
124
125 std::tuple<long> v7_a = {1};
126 std::tuple<long, long> v7_b = {1,2};
127 std::tuple<long, long, long> v7_c = {1,2,3};
128
129 std::tuple<long> v8_a{std::tuple<int>{1}};
130 std::tuple<long, long> v8_b{std::tuple<int,int>{1,2}};
131 std::tuple<long, long, long> v8_c{std::tuple<int,int,int>{1,2,3}};
132
133 std::tuple<long> v9_a = std::tuple<int>{1};
134 std::tuple<long, long> v9_b = std::tuple<int,int>{1,2};
135 std::tuple<long, long, long> v9_c = std::tuple<int,int,int>{1,2,3};
136
137 std::tuple<Explicit> v10_a{v0_a};
138 std::tuple<Explicit, Explicit> v10_b{v0_b};
139 std::tuple<Explicit, Explicit, Explicit> v10_c{v0_c};
140
141 std::tuple<Explicit> v11_a = v0_a; // { dg-error "conversion" }
142 std::tuple<Explicit, Explicit> v11_b = v0_b; // { dg-error "conversion" }
143 std::tuple<Explicit, Explicit, Explicit> v11_c
144 = v0_c; // { dg-error "conversion" }
145
146 std::tuple<long> v12_a{v0_a};
147 std::tuple<long, long> v12_b{v0_b};
148 std::tuple<long, long, long> v12_c{v0_c};
149
150 std::tuple<long> v13_a = v0_a;
151 std::tuple<long, long> v13_b = v0_b;
152 std::tuple<long, long, long> v13_c = v0_c;
153
154 std::tuple<int, int> v14{std::pair<int, int>{1,2}};
155 std::tuple<long, long> v15{std::pair<int, int>{1,2}};
156 std::tuple<Explicit, Explicit> v16{std::pair<int, int>{1,2}};
157
158 std::tuple<int, int> v17 = std::pair<int, int>{1,2};
159 std::tuple<long, long> v18 = std::pair<int, int>{1,2};
160 std::tuple<Explicit, Explicit> v19
161 = std::pair<int, int>{1,2}; // { dg-error "conversion" }
162
163 std::pair<int, int> v20;
164
165 std::tuple<int, int> v21{v20};
166 std::tuple<long, long> v22{v20};
167 std::tuple<Explicit, Explicit> v23{v20};
168
169 std::tuple<int, int> v24 = v20;
170 std::tuple<long, long> v25 = v20;
171 std::tuple<Explicit, Explicit> v26 = v20; // { dg-error "conversion" }
172
173 std::tuple<int> v27_a{std::allocator_arg, std::allocator<int>{}, 1};
174 std::tuple<int, int> v27_b{std::allocator_arg, std::allocator<int>{}, 1, 2};
175 std::tuple<int, int, int> v27_c{std::allocator_arg, std::allocator<int>{}, 1,2,3};
176
177 std::tuple<long> v28_a{std::allocator_arg, std::allocator<int>{}, 1};
178 std::tuple<long, long> v28_b{std::allocator_arg, std::allocator<int>{}, 1, 2};
179 std::tuple<long, long, long>
180 v28_c{std::allocator_arg, std::allocator<int>{}, 1,2,3};
181
182 std::tuple<Explicit> v29_a{std::allocator_arg, std::allocator<int>{}, 1};
183 std::tuple<Explicit, Explicit>
184 v29_b{std::allocator_arg, std::allocator<int>{}, 1, 2};
185 std::tuple<Explicit, Explicit, Explicit>
186 v29_c{std::allocator_arg, std::allocator<int>{}, 1,2,3};
187
188 std::tuple<int> v30_a = {std::allocator_arg, std::allocator<int>{}, 1};
189 std::tuple<int, int> v30_b = {std::allocator_arg, std::allocator<int>{}, 1, 2};
190 std::tuple<int, int, int> v30_c
191 = {std::allocator_arg, std::allocator<int>{}, 1,2,3};
192
193 std::tuple<long> v31_a = {std::allocator_arg, std::allocator<int>{}, 1};
194 std::tuple<long, long> v31_b = {std::allocator_arg, std::allocator<int>{}, 1, 2};
195 std::tuple<long, long, long>
196 v31_c{std::allocator_arg, std::allocator<int>{}, 1,2,3};
197
198 std::tuple<Explicit> v32_a
199 = {std::allocator_arg, std::allocator<int>{ }, 1}; // { dg-error "could not convert" }
200 std::tuple<Explicit, Explicit> v32_b
201 = {std::allocator_arg, std::allocator<int>{}, 1, 2}; // { dg-error "could not convert" }
202 std::tuple<Explicit, Explicit, Explicit> v32_c
203 = {std::allocator_arg, std::allocator<int>{}, 1,2,3}; // { dg-error "could not convert" }
204
205 std::tuple<int, int> v33{std::allocator_arg, std::allocator<int>{},
206 std::pair<int, int>{1, 2}};
207
208 std::tuple<long, long> v34{std::allocator_arg, std::allocator<int>{},
209 std::pair<int, int>{1, 2}};
210
211 std::tuple<Explicit, Explicit>
212 v35{std::allocator_arg, std::allocator<int>{}, std::pair<int, int>{1, 2}};
213
214 std::tuple<int, int> v36 = {std::allocator_arg, std::allocator<int>{},
215 std::pair<int, int>{1, 2}};
216
217 std::tuple<long, long> v37 = {std::allocator_arg, std::allocator<int>{},
218 std::pair<int, int>{1, 2}};
219
220 std::tuple<Explicit, Explicit> v38
221 = {std::allocator_arg, std::allocator<int>{}, std::pair<int, int>{1, 2}}; // { dg-error "could not convert" }
222
223 std::tuple<int, int> v39{std::allocator_arg, std::allocator<int>{}, v20};
224
225 std::tuple<long, long> v40{std::allocator_arg, std::allocator<int>{}, v20};
226
227 std::tuple<Explicit, Explicit>
228 v41{std::allocator_arg, std::allocator<int>{}, v20};
229
230 std::tuple<int, int> v42 = {std::allocator_arg, std::allocator<int>{}, v20};
231
232 std::tuple<long, long> v43 = {std::allocator_arg, std::allocator<int>{}, v20};
233
234 std::tuple<Explicit, Explicit> v44
235 = {std::allocator_arg, std::allocator<int>{ }, v20}; // { dg-error "could not convert" }
236 std::tuple<ExplicitDefault> v45_a{};
237 std::tuple<ExplicitDefault, int> v45_b{};
238
239 std::tuple<ExplicitDefault> v46_a = {}; // { dg-error "could not convert" }
240 std::tuple<ExplicitDefault, int> v46_b = {}; // { dg-error "could not convert" }
241
242 std::tuple<ExplicitDefaultDefault> v47_a{};
243 std::tuple<ExplicitDefaultDefault, int> v47_b{};
244
245 std::tuple<ExplicitDefaultDefault> v48_a = {}; // { dg-error "could not convert" }
246 std::tuple<ExplicitDefaultDefault, int> v48_b = { }; // { dg-error "could not convert" }
247
248
249 struct DeletedCopy
250 {
251 DeletedCopy(int);
252 DeletedCopy(const DeletedCopy&) = delete;
253 };
254
255 std::tuple<DeletedCopy> v45{42};
256 std::tuple<DeletedCopy> v46{std::allocator_arg,
257 std::allocator<DeletedCopy>{}, 42};
258
259 struct Sanity
260 {
261 int v;
262 };
263
264 std::tuple<int, Sanity> v47(3, {42});
265 std::tuple<int, int, Sanity> v48(3, 4, {42});
266 std::tuple<int, Sanity> v49(std::allocator_arg,
267 std::allocator<Sanity>{},
268 3, {42});
269 std::tuple<int, int, Sanity> v50(std::allocator_arg,
270 std::allocator<Sanity>{},
271 3, 4, {42});
272
273 void f8_a(std::tuple<Explicit>) {}
274 void f8_b(std::tuple<Explicit, Explicit>) {}
275 void f8_c(std::tuple<Explicit, Explicit, Explicit>) {}
276
277 void f9_a(std::tuple<long>) {}
278 void f9_b(std::tuple<long, long>) {}
279 void f9_c(std::tuple<long, long, long>) {}
280
281 void f10_a(std::tuple<ExplicitDefault>) {}
282 void f10_b(std::tuple<ExplicitDefault, int>) {}
283
284 void f11_a(std::tuple<ExplicitDefaultDefault>) {}
285 void f11_b(std::tuple<ExplicitDefaultDefault, int>) {}
286
287 void test_arg_passing()
288 {
289 f8_a(v0_a); // { dg-error "could not convert" }
290 f8_b(v0_b); // { dg-error "could not convert" }
291 f8_c(v0_c); // { dg-error "could not convert" }
292 f8_b(v20); // { dg-error "could not convert" }
293
294 f8_a(v1_a);
295 f8_b(v1_b);
296 f8_c(v1_c);
297
298 f8_a({1}); // { dg-error "could not convert" }
299 f8_b({1,2}); // { dg-error "could not convert" }
300 f8_c({1,2,3}); // { dg-error "could not convert" }
301
302 f8_a(std::tuple<Explicit>{});
303 f8_b(std::tuple<Explicit, Explicit>{});
304 f8_c(std::tuple<Explicit, Explicit, Explicit>{});
305
306 f8_a(std::tuple<int>{}); // { dg-error "could not convert" }
307 f8_b(std::tuple<int, int>{}); // { dg-error "could not convert" }
308 f8_c(std::tuple<int, int, int>{}); // { dg-error "could not convert" }
309 f8_b(std::pair<int, int>{}); // { dg-error "could not convert" }
310
311 f9_a(v0_a);
312 f9_b(v0_b);
313 f9_c(v0_c);
314 f9_b(v20);
315
316 f9_a(v6_a);
317 f9_b(v6_b);
318 f9_c(v6_c);
319
320 f9_a({1});
321 f9_b({1,2});
322 f9_c({1,2,3});
323
324 f9_a(std::tuple<int>{});
325 f9_b(std::tuple<int, int>{});
326 f9_c(std::tuple<int, int, int>{});
327 f9_b(std::pair<int, int>{});
328
329 f9_a(std::tuple<long>{});
330 f9_b(std::tuple<long, long>{});
331 f9_c(std::tuple<long, long, long>{});
332
333 f10_a({}); // { dg-error "could not convert" }
334 f10_b({}); // { dg-error "could not convert" }
335 f11_a({}); // { dg-error "could not convert" }
336 f11_b({}); // { dg-error "could not convert" }
337
338 f10_a(std::tuple<ExplicitDefault>{});
339 f10_b(std::tuple<ExplicitDefault, int>{});
340 f11_a(std::tuple<ExplicitDefaultDefault>{});
341 f11_b(std::tuple<ExplicitDefaultDefault, int>{});
342 }