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