]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/20_util/pair/cons/explicit_construct.cc
1 // { dg-do compile { target c++11 } }
3 // Copyright (C) 2015-2022 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/>.
25 explicit Explicit(int) {}
28 struct ExplicitDefault
30 explicit ExplicitDefault() {}
33 struct ExplicitDefaultDefault
35 explicit ExplicitDefaultDefault() = default;
38 std::pair
<int, int> f1() {return {1,2};}
40 std::pair
<Explicit
, Explicit
> f2() {return {1,2};} // { dg-error "could not convert" }
42 std::pair
<long, long> f3() {return std::pair
<int, int>{1,2};}
44 std::pair
<Explicit
, Explicit
> f4()
46 return std::pair
<int, int>{1,2}; // { dg-error "could not convert" }
49 std::pair
<long, long> f5() {return {1,2};}
51 std::pair
<int, int> v0
{1,2};
53 std::pair
<Explicit
, Explicit
> v1
{1,2};
55 std::pair
<Explicit
, Explicit
> v2
= {1,2}; // { dg-error "could not convert" }
57 std::pair
<Explicit
, Explicit
> v3
{std::pair
<int,int>{1,2}};
59 std::pair
<Explicit
, Explicit
> v4
=
60 std::pair
<int,int>{1,2}; // { dg-error "conversion" }
62 std::pair
<char *, char *> v5(0,0);
64 std::pair
<long, long> v6
{1,2};
66 std::pair
<long, long> v7
= {1,2};
68 std::pair
<long, long> v8
{std::pair
<int,int>{1,2}};
70 std::pair
<long, long> v9
= std::pair
<int,int>{1,2};
72 std::pair
<Explicit
, Explicit
> v10
{v0
};
74 std::pair
<Explicit
, Explicit
> v11
= v0
; // { dg-error "conversion" }
76 std::pair
<long, long> v12
{v0
};
78 std::pair
<long, long> v13
= v0
;
80 void f6(std::pair
<Explicit
, Explicit
>) {}
82 void f7(std::pair
<long, long>) {}
84 std::pair
<ExplicitDefault
, int> f8()
86 return {}; // { dg-error "convert" }
89 std::pair
<ExplicitDefaultDefault
, int> f9()
91 return {}; // { dg-error "convert" }
94 void f10(std::pair
<ExplicitDefault
, int>) {}
96 void f11(std::pair
<ExplicitDefaultDefault
, int>) {}
98 void test_arg_passing()
100 f6(v0
); // { dg-error "could not convert" }
102 f6({1,2}); // { dg-error "could not convert" }
103 f6(std::pair
<Explicit
, Explicit
>{});
104 f6(std::pair
<int, int>{}); // { dg-error "could not convert" }
108 f7(std::pair
<int, int>{});
109 f7(std::pair
<long, long>{});
110 f10({}); // { dg-error "convert" }
111 f11({}); // { dg-error "convert" }
112 f10(std::pair
<ExplicitDefault
, int>{});
113 f11(std::pair
<ExplicitDefaultDefault
, int>{});
118 MoveOnly() = default;
119 MoveOnly(MoveOnly
&&) {}
122 struct ExplicitMoveOnly
124 ExplicitMoveOnly() = default;
125 ExplicitMoveOnly(ExplicitMoveOnly
&&) {}
126 explicit ExplicitMoveOnly(MoveOnly
&&) {}
129 std::pair
<int*, ExplicitMoveOnly
> v14
{nullptr, MoveOnly
{}};
130 std::pair
<ExplicitMoveOnly
, int*> v15
{MoveOnly
{}, nullptr};
132 std::pair
<int*, ExplicitMoveOnly
> v16
=
133 {nullptr, MoveOnly
{}}; // { dg-error "could not convert" }
134 std::pair
<ExplicitMoveOnly
, int*> v17
=
135 {MoveOnly
{}, nullptr}; // { dg-error "could not convert" }