]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/20_util/pair/cons/explicit_construct.cc
2 // { dg-options "-std=gnu++11" }
4 // Copyright (C) 2015-2016 Free Software Foundation, Inc.
6 // This file is part of the GNU ISO C++ Library. This library is free
7 // software; you can redistribute it and/or modify it under the
8 // terms of the GNU General Public License as published by the
9 // Free Software Foundation; either version 3, or (at your option)
12 // This library is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
17 // You should have received a copy of the GNU General Public License along
18 // with this library; see the file COPYING3. If not see
19 // <http://www.gnu.org/licenses/>.
26 explicit Explicit(int) {}
29 struct ExplicitDefault
31 explicit ExplicitDefault() {}
34 struct ExplicitDefaultDefault
36 explicit ExplicitDefaultDefault() = default;
39 std::pair
<int, int> f1() {return {1,2};}
41 std::pair
<Explicit
, Explicit
> f2() {return {1,2};} // { dg-error "explicit" }
43 std::pair
<long, long> f3() {return std::pair
<int, int>{1,2};}
45 std::pair
<Explicit
, Explicit
> f4()
47 return std::pair
<int, int>{1,2}; // { dg-error "could not convert" }
50 std::pair
<long, long> f5() {return {1,2};}
52 std::pair
<int, int> v0
{1,2};
54 std::pair
<Explicit
, Explicit
> v1
{1,2};
56 std::pair
<Explicit
, Explicit
> v2
= {1,2}; // { dg-error "explicit" }
58 std::pair
<Explicit
, Explicit
> v3
{std::pair
<int,int>{1,2}};
60 std::pair
<Explicit
, Explicit
> v4
=
61 std::pair
<int,int>{1,2}; // { dg-error "conversion" }
63 std::pair
<char *, char *> v5(0,0);
65 std::pair
<long, long> v6
{1,2};
67 std::pair
<long, long> v7
= {1,2};
69 std::pair
<long, long> v8
{std::pair
<int,int>{1,2}};
71 std::pair
<long, long> v9
= std::pair
<int,int>{1,2};
73 std::pair
<Explicit
, Explicit
> v10
{v0
};
75 std::pair
<Explicit
, Explicit
> v11
= v0
; // { dg-error "conversion" }
77 std::pair
<long, long> v12
{v0
};
79 std::pair
<long, long> v13
= v0
;
81 void f6(std::pair
<Explicit
, Explicit
>) {}
83 void f7(std::pair
<long, long>) {}
85 std::pair
<ExplicitDefault
, int> f8()
87 return {}; // { dg-error "explicit" }
90 std::pair
<ExplicitDefaultDefault
, int> f9()
92 return {}; // { dg-error "explicit" }
95 void f10(std::pair
<ExplicitDefault
, int>) {}
97 void f11(std::pair
<ExplicitDefaultDefault
, int>) {}
99 void test_arg_passing()
101 f6(v0
); // { dg-error "could not convert" }
103 f6({1,2}); // { dg-error "explicit" }
104 f6(std::pair
<Explicit
, Explicit
>{});
105 f6(std::pair
<int, int>{}); // { dg-error "could not convert" }
109 f7(std::pair
<int, int>{});
110 f7(std::pair
<long, long>{});
111 f10({}); // { dg-error "explicit" }
112 f11({}); // { dg-error "explicit" }
113 f10(std::pair
<ExplicitDefault
, int>{});
114 f11(std::pair
<ExplicitDefaultDefault
, int>{});
119 MoveOnly() = default;
120 MoveOnly(MoveOnly
&&) {}
123 struct ExplicitMoveOnly
125 ExplicitMoveOnly() = default;
126 ExplicitMoveOnly(ExplicitMoveOnly
&&) {}
127 explicit ExplicitMoveOnly(MoveOnly
&&) {}
130 std::pair
<int*, ExplicitMoveOnly
> v14
{0, MoveOnly
{}};
131 std::pair
<ExplicitMoveOnly
, int*> v15
{MoveOnly
{}, 0};
133 std::pair
<int*, ExplicitMoveOnly
> v16
=
134 {0, MoveOnly
{}}; // { dg-error "explicit" }
135 std::pair
<ExplicitMoveOnly
, int*> v17
=
136 {MoveOnly
{}, 0}; // { dg-error "explicit" }