]>
git.ipfire.org Git - thirdparty/gcc.git/blob - 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 }
5 // Copyright (C) 2015-2023 Free Software Foundation, Inc.
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)
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.
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/>.
30 explicit Explicit(int) {}
33 struct ExplicitDefault
35 explicit ExplicitDefault() {}
38 struct ExplicitDefaultDefault
40 explicit ExplicitDefaultDefault() = default;
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};}
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" }
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};}
58 std::tuple
<Explicit
> f4_a()
60 return std::tuple
<int>{1}; // { dg-error "could not convert" }
62 std::tuple
<Explicit
, Explicit
> f4_b()
64 return std::tuple
<int, int>{1,2}; // { dg-error "could not convert" }
66 std::tuple
<Explicit
, Explicit
, Explicit
> f4_c()
68 return std::tuple
<int, int,int>{1,2,3}; // { dg-error "could not convert" }
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};}
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" }
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" }
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" }
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};
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};
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" }
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}};
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" }
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};
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};
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}};
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};
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
};
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" }
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
};
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
;
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}};
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" }
163 std::pair
<int, int> v20
;
165 std::tuple
<int, int> v21
{v20
};
166 std::tuple
<long, long> v22
{v20
};
167 std::tuple
<Explicit
, Explicit
> v23
{v20
};
169 std::tuple
<int, int> v24
= v20
;
170 std::tuple
<long, long> v25
= v20
;
171 std::tuple
<Explicit
, Explicit
> v26
= v20
; // { dg-error "conversion" }
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};
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};
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};
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};
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};
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" }
205 std::tuple
<int, int> v33
{std::allocator_arg
, std::allocator
<int>{},
206 std::pair
<int, int>{1, 2}};
208 std::tuple
<long, long> v34
{std::allocator_arg
, std::allocator
<int>{},
209 std::pair
<int, int>{1, 2}};
211 std::tuple
<Explicit
, Explicit
>
212 v35
{std::allocator_arg
, std::allocator
<int>{}, std::pair
<int, int>{1, 2}};
214 std::tuple
<int, int> v36
= {std::allocator_arg
, std::allocator
<int>{},
215 std::pair
<int, int>{1, 2}};
217 std::tuple
<long, long> v37
= {std::allocator_arg
, std::allocator
<int>{},
218 std::pair
<int, int>{1, 2}};
220 std::tuple
<Explicit
, Explicit
> v38
221 = {std::allocator_arg
, std::allocator
<int>{}, std::pair
<int, int>{1, 2}}; // { dg-error "could not convert" }
223 std::tuple
<int, int> v39
{std::allocator_arg
, std::allocator
<int>{}, v20
};
225 std::tuple
<long, long> v40
{std::allocator_arg
, std::allocator
<int>{}, v20
};
227 std::tuple
<Explicit
, Explicit
>
228 v41
{std::allocator_arg
, std::allocator
<int>{}, v20
};
230 std::tuple
<int, int> v42
= {std::allocator_arg
, std::allocator
<int>{}, v20
};
232 std::tuple
<long, long> v43
= {std::allocator_arg
, std::allocator
<int>{}, v20
};
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
{};
239 std::tuple
<ExplicitDefault
> v46_a
= {}; // { dg-error "could not convert" }
240 std::tuple
<ExplicitDefault
, int> v46_b
= {}; // { dg-error "could not convert" }
242 std::tuple
<ExplicitDefaultDefault
> v47_a
{};
243 std::tuple
<ExplicitDefaultDefault
, int> v47_b
{};
245 std::tuple
<ExplicitDefaultDefault
> v48_a
= {}; // { dg-error "could not convert" }
246 std::tuple
<ExplicitDefaultDefault
, int> v48_b
= { }; // { dg-error "could not convert" }
252 DeletedCopy(const DeletedCopy
&) = delete;
255 std::tuple
<DeletedCopy
> v45
{42};
256 std::tuple
<DeletedCopy
> v46
{std::allocator_arg
,
257 std::allocator
<DeletedCopy
>{}, 42};
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
>{},
269 std::tuple
<int, int, Sanity
> v50(std::allocator_arg
,
270 std::allocator
<Sanity
>{},
273 void f8_a(std::tuple
<Explicit
>) {}
274 void f8_b(std::tuple
<Explicit
, Explicit
>) {}
275 void f8_c(std::tuple
<Explicit
, Explicit
, Explicit
>) {}
277 void f9_a(std::tuple
<long>) {}
278 void f9_b(std::tuple
<long, long>) {}
279 void f9_c(std::tuple
<long, long, long>) {}
281 void f10_a(std::tuple
<ExplicitDefault
>) {}
282 void f10_b(std::tuple
<ExplicitDefault
, int>) {}
284 void f11_a(std::tuple
<ExplicitDefaultDefault
>) {}
285 void f11_b(std::tuple
<ExplicitDefaultDefault
, int>) {}
287 void test_arg_passing()
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" }
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" }
302 f8_a(std::tuple
<Explicit
>{});
303 f8_b(std::tuple
<Explicit
, Explicit
>{});
304 f8_c(std::tuple
<Explicit
, Explicit
, Explicit
>{});
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" }
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>{});
329 f9_a(std::tuple
<long>{});
330 f9_b(std::tuple
<long, long>{});
331 f9_c(std::tuple
<long, long, long>{});
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" }
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>{});