]>
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 } }
3 // Copyright (C) 2015-2020 Free Software Foundation, Inc.
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)
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.
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/>.
28 explicit Explicit(int) {}
31 struct ExplicitDefault
33 explicit ExplicitDefault() {}
36 struct ExplicitDefaultDefault
38 explicit ExplicitDefaultDefault() = default;
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};}
45 std::tuple
<Explicit
> f2_a()
46 {return {1};} // { dg-error "could not convert" }
47 std::tuple
<Explicit
, Explicit
> f2_b()
48 {return {1,2};} // { dg-error "could not convert" }
49 std::tuple
<Explicit
, Explicit
, Explicit
> f2_c()
50 {return {1,2,3};} // { dg-error "could not convert" }
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};}
56 std::tuple
<Explicit
> f4_a()
58 return std::tuple
<int>{1}; // { dg-error "could not convert" }
60 std::tuple
<Explicit
, Explicit
> f4_b()
62 return std::tuple
<int, int>{1,2}; // { dg-error "could not convert" }
64 std::tuple
<Explicit
, Explicit
, Explicit
> f4_c()
66 return std::tuple
<int, int,int>{1,2,3}; // { dg-error "could not convert" }
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};}
73 std::tuple
<ExplicitDefault
> f6_a()
74 {return {};} // { dg-error "could not convert" }
75 std::tuple
<ExplicitDefault
, ExplicitDefault
> f6_b()
76 {return {};} // { dg-error "could not convert" }
77 std::tuple
<ExplicitDefault
, ExplicitDefault
, ExplicitDefault
> f6_c()
78 {return {};} // { dg-error "could not convert" }
79 std::tuple
<ExplicitDefault
, int> f6_d()
80 {return {};} // { dg-error "could not convert" }
82 std::tuple
<ExplicitDefaultDefault
> f7_a()
83 {return {};} // { dg-error "could not convert" }
84 std::tuple
<ExplicitDefaultDefault
, ExplicitDefaultDefault
> f7_b()
85 {return {};} // { dg-error "could not convert" }
86 std::tuple
<ExplicitDefaultDefault
,
87 ExplicitDefaultDefault
,
88 ExplicitDefaultDefault
> f7_c()
89 {return {};} // { dg-error "could not convert" }
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" }
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};
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};
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" }
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}};
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" }
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};
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};
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}};
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};
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
};
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" }
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
};
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
;
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}};
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" }
161 std::pair
<int, int> v20
;
163 std::tuple
<int, int> v21
{v20
};
164 std::tuple
<long, long> v22
{v20
};
165 std::tuple
<Explicit
, Explicit
> v23
{v20
};
167 std::tuple
<int, int> v24
= v20
;
168 std::tuple
<long, long> v25
= v20
;
169 std::tuple
<Explicit
, Explicit
> v26
= v20
; // { dg-error "conversion" }
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};
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};
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};
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};
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};
196 std::tuple
<Explicit
> v32_a
197 = {std::allocator_arg
, std::allocator
<int>{ }, 1}; // { dg-error "could not convert" }
198 std::tuple
<Explicit
, Explicit
> v32_b
199 = {std::allocator_arg
, std::allocator
<int>{}, 1, 2}; // { dg-error "could not convert" }
200 std::tuple
<Explicit
, Explicit
, Explicit
> v32_c
201 = {std::allocator_arg
, std::allocator
<int>{}, 1,2,3}; // { dg-error "could not convert" }
203 std::tuple
<int, int> v33
{std::allocator_arg
, std::allocator
<int>{},
204 std::pair
<int, int>{1, 2}};
206 std::tuple
<long, long> v34
{std::allocator_arg
, std::allocator
<int>{},
207 std::pair
<int, int>{1, 2}};
209 std::tuple
<Explicit
, Explicit
>
210 v35
{std::allocator_arg
, std::allocator
<int>{}, std::pair
<int, int>{1, 2}};
212 std::tuple
<int, int> v36
= {std::allocator_arg
, std::allocator
<int>{},
213 std::pair
<int, int>{1, 2}};
215 std::tuple
<long, long> v37
= {std::allocator_arg
, std::allocator
<int>{},
216 std::pair
<int, int>{1, 2}};
218 std::tuple
<Explicit
, Explicit
> v38
219 = {std::allocator_arg
, std::allocator
<int>{}, std::pair
<int, int>{1, 2}}; // { dg-error "could not convert" }
221 std::tuple
<int, int> v39
{std::allocator_arg
, std::allocator
<int>{}, v20
};
223 std::tuple
<long, long> v40
{std::allocator_arg
, std::allocator
<int>{}, v20
};
225 std::tuple
<Explicit
, Explicit
>
226 v41
{std::allocator_arg
, std::allocator
<int>{}, v20
};
228 std::tuple
<int, int> v42
= {std::allocator_arg
, std::allocator
<int>{}, v20
};
230 std::tuple
<long, long> v43
= {std::allocator_arg
, std::allocator
<int>{}, v20
};
232 std::tuple
<Explicit
, Explicit
> v44
233 = {std::allocator_arg
, std::allocator
<int>{ }, v20
}; // { dg-error "could not convert" }
234 std::tuple
<ExplicitDefault
> v45_a
{};
235 std::tuple
<ExplicitDefault
, int> v45_b
{};
237 std::tuple
<ExplicitDefault
> v46_a
= {}; // { dg-error "could not convert" }
238 std::tuple
<ExplicitDefault
, int> v46_b
= {}; // { dg-error "could not convert" }
240 std::tuple
<ExplicitDefaultDefault
> v47_a
{};
241 std::tuple
<ExplicitDefaultDefault
, int> v47_b
{};
243 std::tuple
<ExplicitDefaultDefault
> v48_a
= {}; // { dg-error "could not convert" }
244 std::tuple
<ExplicitDefaultDefault
, int> v48_b
= { }; // { dg-error "could not convert" }
250 DeletedCopy(const DeletedCopy
&) = delete;
253 std::tuple
<DeletedCopy
> v45
{42};
254 std::tuple
<DeletedCopy
> v46
{std::allocator_arg
,
255 std::allocator
<DeletedCopy
>{}, 42};
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
>{},
267 std::tuple
<int, int, Sanity
> v50(std::allocator_arg
,
268 std::allocator
<Sanity
>{},
271 void f8_a(std::tuple
<Explicit
>) {}
272 void f8_b(std::tuple
<Explicit
, Explicit
>) {}
273 void f8_c(std::tuple
<Explicit
, Explicit
, Explicit
>) {}
275 void f9_a(std::tuple
<long>) {}
276 void f9_b(std::tuple
<long, long>) {}
277 void f9_c(std::tuple
<long, long, long>) {}
279 void f10_a(std::tuple
<ExplicitDefault
>) {}
280 void f10_b(std::tuple
<ExplicitDefault
, int>) {}
282 void f11_a(std::tuple
<ExplicitDefaultDefault
>) {}
283 void f11_b(std::tuple
<ExplicitDefaultDefault
, int>) {}
285 void test_arg_passing()
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" }
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" }
300 f8_a(std::tuple
<Explicit
>{});
301 f8_b(std::tuple
<Explicit
, Explicit
>{});
302 f8_c(std::tuple
<Explicit
, Explicit
, Explicit
>{});
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" }
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>{});
327 f9_a(std::tuple
<long>{});
328 f9_b(std::tuple
<long, long>{});
329 f9_c(std::tuple
<long, long, long>{});
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" }
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>{});