]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/20_util/tuple/cons/explicit_construct.cc
Use effective-target instead of -std options
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 20_util / tuple / cons / explicit_construct.cc
CommitLineData
52066eae 1// { dg-do compile { target c++11 } }
bf7818bf 2
818ab71a 3// Copyright (C) 2015-2016 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
25struct Explicit
26{
27 Explicit() = default;
28 explicit Explicit(int) {}
29};
30
f7632193
VV
31struct ExplicitDefault
32{
33 explicit ExplicitDefault() {}
34};
35
36struct ExplicitDefaultDefault
37{
38 explicit ExplicitDefaultDefault() = default;
39};
40
bf7818bf
VV
41std::tuple<int> f1a() {return {1};}
42std::tuple<int, int> f1b() {return {1,2};}
43std::tuple<int, int, int> f1c() {return {1,2,3};}
44
f7632193
VV
45std::tuple<Explicit> f2_a()
46{return {1};} // { dg-error "explicit" }
47std::tuple<Explicit, Explicit> f2_b()
48{return {1,2};} // { dg-error "explicit" }
49std::tuple<Explicit, Explicit, Explicit> f2_c()
50{return {1,2,3};} // { dg-error "explicit" }
bf7818bf
VV
51
52std::tuple<long> f3_a() {return std::tuple<int>{1};}
53std::tuple<long, long> f3_b() {return std::tuple<int, int>{1,2};}
54std::tuple<long, long, long> f3_c() {return std::tuple<int, int, int>{1,2,3};}
55
56std::tuple<Explicit> f4_a()
57{
58 return std::tuple<int>{1}; // { dg-error "could not convert" }
59}
60std::tuple<Explicit, Explicit> f4_b()
61{
62 return std::tuple<int, int>{1,2}; // { dg-error "could not convert" }
63}
64std::tuple<Explicit, Explicit, Explicit> f4_c()
65{
66 return std::tuple<int, int,int>{1,2,3}; // { dg-error "could not convert" }
67}
68
69std::tuple<long> f5_a() {return {1};}
70std::tuple<long, long> f5_b() {return {1,2};}
71std::tuple<long, long, long> f5_c() {return {1,2,3};}
72
f7632193
VV
73std::tuple<ExplicitDefault> f6_a()
74{return {};} // { dg-error "explicit" }
75std::tuple<ExplicitDefault, ExplicitDefault> f6_b()
76{return {};} // { dg-error "explicit" }
77std::tuple<ExplicitDefault, ExplicitDefault, ExplicitDefault> f6_c()
78{return {};} // { dg-error "explicit" }
79std::tuple<ExplicitDefault, int> f6_d()
80{return {};} // { dg-error "explicit" }
81
82std::tuple<ExplicitDefaultDefault> f7_a()
83{return {};} // { dg-error "explicit" }
84std::tuple<ExplicitDefaultDefault, ExplicitDefaultDefault> f7_b()
85{return {};} // { dg-error "explicit" }
86std::tuple<ExplicitDefaultDefault,
87 ExplicitDefaultDefault,
88 ExplicitDefaultDefault> f7_c()
89{return {};} // { dg-error "explicit" }
90
bf7818bf
VV
91std::tuple<int, int> fp1() {return std::pair<int, int>{1,2}; }
92std::tuple<long, long> fp2() {return std::pair<int, int>{1,2}; }
93std::tuple<Explicit, Explicit> fp3()
94 {return std::pair<int, int>{1,2}; } // { dg-error "could not convert" }
95
96std::tuple<int> v0_a{1};
97std::tuple<int, int> v0_b{1,2};
98std::tuple<int, int, int> v0_c{1,2,3};
99
100std::tuple<Explicit> v1_a{1};
101std::tuple<Explicit, Explicit> v1_b{1,2};
102std::tuple<Explicit, Explicit, Explicit> v1_c{1,2,3};
103
104std::tuple<Explicit> v2_a = {1}; // { dg-error "explicit" }
105std::tuple<Explicit, Explicit> v2_b = {1,2}; // { dg-error "explicit" }
106std::tuple<Explicit, Explicit, Explicit> v2_c = {1,2,3}; // { dg-error "explicit" }
107
108std::tuple<Explicit> v3_a{std::tuple<int>{1}};
109std::tuple<Explicit, Explicit> v3_b{std::tuple<int,int>{1,2}};
110std::tuple<Explicit, Explicit, Explicit> v3_c{std::tuple<int,int,int>{1,2,3}};
111
112std::tuple<Explicit, Explicit> v4_a =
113 std::tuple<int>{1}; // { dg-error "conversion" }
114std::tuple<Explicit, Explicit> v4_b =
115 std::tuple<int,int>{1,2}; // { dg-error "conversion" }
116std::tuple<Explicit, Explicit, Explicit> v4_c =
117 std::tuple<int,int,int>{1,2,3}; // { dg-error "conversion" }
118
119std::tuple<long> v6_a{1};
120std::tuple<long, long> v6_b{1,2};
121std::tuple<long, long, long> v6_c{1,2,3};
122
123std::tuple<long> v7_a = {1};
124std::tuple<long, long> v7_b = {1,2};
125std::tuple<long, long, long> v7_c = {1,2,3};
126
127std::tuple<long> v8_a{std::tuple<int>{1}};
128std::tuple<long, long> v8_b{std::tuple<int,int>{1,2}};
129std::tuple<long, long, long> v8_c{std::tuple<int,int,int>{1,2,3}};
130
131std::tuple<long> v9_a = std::tuple<int>{1};
132std::tuple<long, long> v9_b = std::tuple<int,int>{1,2};
133std::tuple<long, long, long> v9_c = std::tuple<int,int,int>{1,2,3};
134
135std::tuple<Explicit> v10_a{v0_a};
136std::tuple<Explicit, Explicit> v10_b{v0_b};
137std::tuple<Explicit, Explicit, Explicit> v10_c{v0_c};
138
139std::tuple<Explicit> v11_a = v0_a; // { dg-error "conversion" }
140std::tuple<Explicit, Explicit> v11_b = v0_b; // { dg-error "conversion" }
141std::tuple<Explicit, Explicit, Explicit> v11_c
142 = v0_c; // { dg-error "conversion" }
143
144std::tuple<long> v12_a{v0_a};
145std::tuple<long, long> v12_b{v0_b};
146std::tuple<long, long, long> v12_c{v0_c};
147
148std::tuple<long> v13_a = v0_a;
149std::tuple<long, long> v13_b = v0_b;
150std::tuple<long, long, long> v13_c = v0_c;
151
152std::tuple<int, int> v14{std::pair<int, int>{1,2}};
153std::tuple<long, long> v15{std::pair<int, int>{1,2}};
154std::tuple<Explicit, Explicit> v16{std::pair<int, int>{1,2}};
155
156std::tuple<int, int> v17 = std::pair<int, int>{1,2};
157std::tuple<long, long> v18 = std::pair<int, int>{1,2};
158std::tuple<Explicit, Explicit> v19
159 = std::pair<int, int>{1,2}; // { dg-error "conversion" }
160
161std::pair<int, int> v20;
162
163std::tuple<int, int> v21{v20};
164std::tuple<long, long> v22{v20};
165std::tuple<Explicit, Explicit> v23{v20};
166
167std::tuple<int, int> v24 = v20;
168std::tuple<long, long> v25 = v20;
169std::tuple<Explicit, Explicit> v26 = v20; // { dg-error "conversion" }
170
171std::tuple<int> v27_a{std::allocator_arg, std::allocator<int>{}, 1};
172std::tuple<int, int> v27_b{std::allocator_arg, std::allocator<int>{}, 1, 2};
173std::tuple<int, int, int> v27_c{std::allocator_arg, std::allocator<int>{}, 1,2,3};
174
175std::tuple<long> v28_a{std::allocator_arg, std::allocator<int>{}, 1};
176std::tuple<long, long> v28_b{std::allocator_arg, std::allocator<int>{}, 1, 2};
177std::tuple<long, long, long>
178 v28_c{std::allocator_arg, std::allocator<int>{}, 1,2,3};
179
180std::tuple<Explicit> v29_a{std::allocator_arg, std::allocator<int>{}, 1};
181std::tuple<Explicit, Explicit>
182 v29_b{std::allocator_arg, std::allocator<int>{}, 1, 2};
183std::tuple<Explicit, Explicit, Explicit>
184 v29_c{std::allocator_arg, std::allocator<int>{}, 1,2,3};
185
186std::tuple<int> v30_a = {std::allocator_arg, std::allocator<int>{}, 1};
187std::tuple<int, int> v30_b = {std::allocator_arg, std::allocator<int>{}, 1, 2};
188std::tuple<int, int, int> v30_c
189 = {std::allocator_arg, std::allocator<int>{}, 1,2,3};
190
191std::tuple<long> v31_a = {std::allocator_arg, std::allocator<int>{}, 1};
192std::tuple<long, long> v31_b = {std::allocator_arg, std::allocator<int>{}, 1, 2};
193std::tuple<long, long, long>
194 v31_c{std::allocator_arg, std::allocator<int>{}, 1,2,3};
195
196std::tuple<Explicit> v32_a
f7632193 197 = {std::allocator_arg, std::allocator<int>{ }, 1}; // { dg-error "explicit" }
bf7818bf
VV
198std::tuple<Explicit, Explicit> v32_b
199 = {std::allocator_arg, std::allocator<int>{}, 1, 2}; // { dg-error "explicit" }
200std::tuple<Explicit, Explicit, Explicit> v32_c
201 = {std::allocator_arg, std::allocator<int>{}, 1,2,3}; // { dg-error "explicit" }
202
203std::tuple<int, int> v33{std::allocator_arg, std::allocator<int>{},
204 std::pair<int, int>{1, 2}};
205
206std::tuple<long, long> v34{std::allocator_arg, std::allocator<int>{},
207 std::pair<int, int>{1, 2}};
208
209std::tuple<Explicit, Explicit>
210 v35{std::allocator_arg, std::allocator<int>{}, std::pair<int, int>{1, 2}};
211
212std::tuple<int, int> v36 = {std::allocator_arg, std::allocator<int>{},
213 std::pair<int, int>{1, 2}};
214
215std::tuple<long, long> v37 = {std::allocator_arg, std::allocator<int>{},
216 std::pair<int, int>{1, 2}};
217
218std::tuple<Explicit, Explicit> v38
219= {std::allocator_arg, std::allocator<int>{}, std::pair<int, int>{1, 2}}; // { dg-error "explicit" }
220
221std::tuple<int, int> v39{std::allocator_arg, std::allocator<int>{}, v20};
222
223std::tuple<long, long> v40{std::allocator_arg, std::allocator<int>{}, v20};
224
225std::tuple<Explicit, Explicit>
226 v41{std::allocator_arg, std::allocator<int>{}, v20};
227
228std::tuple<int, int> v42 = {std::allocator_arg, std::allocator<int>{}, v20};
229
230std::tuple<long, long> v43 = {std::allocator_arg, std::allocator<int>{}, v20};
231
232std::tuple<Explicit, Explicit> v44
f7632193
VV
233= {std::allocator_arg, std::allocator<int>{ }, v20}; // { dg-error "explicit" }
234std::tuple<ExplicitDefault> v45_a{};
235std::tuple<ExplicitDefault, int> v45_b{};
236
237std::tuple<ExplicitDefault> v46_a = {}; // { dg-error "explicit" }
238std::tuple<ExplicitDefault, int> v46_b = {}; // { dg-error "explicit" }
239
240std::tuple<ExplicitDefaultDefault> v47_a{};
241std::tuple<ExplicitDefaultDefault, int> v47_b{};
242
243std::tuple<ExplicitDefaultDefault> v48_a = {}; // { dg-error "explicit" }
244std::tuple<ExplicitDefaultDefault, int> v48_b = { }; // { dg-error "explicit" }
245
bf7818bf
VV
246
247struct DeletedCopy
248{
249 DeletedCopy(int);
250 DeletedCopy(const DeletedCopy&) = delete;
251};
252
253std::tuple<DeletedCopy> v45{42};
254std::tuple<DeletedCopy> v46{std::allocator_arg,
255 std::allocator<DeletedCopy>{}, 42};
256
257struct Sanity
258{
259 int v;
260};
261
262std::tuple<int, Sanity> v47(3, {42});
263std::tuple<int, int, Sanity> v48(3, 4, {42});
264std::tuple<int, Sanity> v49(std::allocator_arg,
265 std::allocator<Sanity>{},
266 3, {42});
267std::tuple<int, int, Sanity> v50(std::allocator_arg,
268 std::allocator<Sanity>{},
269 3, 4, {42});
270
f7632193
VV
271void f8_a(std::tuple<Explicit>) {}
272void f8_b(std::tuple<Explicit, Explicit>) {}
273void f8_c(std::tuple<Explicit, Explicit, Explicit>) {}
274
275void f9_a(std::tuple<long>) {}
276void f9_b(std::tuple<long, long>) {}
277void f9_c(std::tuple<long, long, long>) {}
278
279void f10_a(std::tuple<ExplicitDefault>) {}
280void f10_b(std::tuple<ExplicitDefault, int>) {}
bf7818bf 281
f7632193
VV
282void f11_a(std::tuple<ExplicitDefaultDefault>) {}
283void f11_b(std::tuple<ExplicitDefaultDefault, int>) {}
bf7818bf
VV
284
285void 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
296 f8_a({1}); // { dg-error "explicit" }
297 f8_b({1,2}); // { dg-error "explicit" }
298 f8_c({1,2,3}); // { dg-error "explicit" }
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
331 f10_a({}); // { dg-error "explicit" }
332 f10_b({}); // { dg-error "explicit" }
333 f11_a({}); // { dg-error "explicit" }
334 f11_b({}); // { dg-error "explicit" }
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}