]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/20_util/pair/cons/explicit_construct.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 20_util / pair / cons / explicit_construct.cc
1 // { dg-do compile }
2 // { dg-options "-std=gnu++11" }
3
4 // Copyright (C) 2015-2016 Free Software Foundation, Inc.
5 //
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)
10 // any later version.
11 //
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.
16 //
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/>.
20
21 #include <utility>
22
23 struct Explicit
24 {
25 Explicit() = default;
26 explicit Explicit(int) {}
27 };
28
29 struct ExplicitDefault
30 {
31 explicit ExplicitDefault() {}
32 };
33
34 struct ExplicitDefaultDefault
35 {
36 explicit ExplicitDefaultDefault() = default;
37 };
38
39 std::pair<int, int> f1() {return {1,2};}
40
41 std::pair<Explicit, Explicit> f2() {return {1,2};} // { dg-error "explicit" }
42
43 std::pair<long, long> f3() {return std::pair<int, int>{1,2};}
44
45 std::pair<Explicit, Explicit> f4()
46 {
47 return std::pair<int, int>{1,2}; // { dg-error "could not convert" }
48 }
49
50 std::pair<long, long> f5() {return {1,2};}
51
52 std::pair<int, int> v0{1,2};
53
54 std::pair<Explicit, Explicit> v1{1,2};
55
56 std::pair<Explicit, Explicit> v2 = {1,2}; // { dg-error "explicit" }
57
58 std::pair<Explicit, Explicit> v3{std::pair<int,int>{1,2}};
59
60 std::pair<Explicit, Explicit> v4 =
61 std::pair<int,int>{1,2}; // { dg-error "conversion" }
62
63 std::pair<char *, char *> v5(0,0);
64
65 std::pair<long, long> v6{1,2};
66
67 std::pair<long, long> v7 = {1,2};
68
69 std::pair<long, long> v8{std::pair<int,int>{1,2}};
70
71 std::pair<long, long> v9 = std::pair<int,int>{1,2};
72
73 std::pair<Explicit, Explicit> v10{v0};
74
75 std::pair<Explicit, Explicit> v11 = v0; // { dg-error "conversion" }
76
77 std::pair<long, long> v12{v0};
78
79 std::pair<long, long> v13 = v0;
80
81 void f6(std::pair<Explicit, Explicit>) {}
82
83 void f7(std::pair<long, long>) {}
84
85 std::pair<ExplicitDefault, int> f8()
86 {
87 return {}; // { dg-error "explicit" }
88 }
89
90 std::pair<ExplicitDefaultDefault, int> f9()
91 {
92 return {}; // { dg-error "explicit" }
93 }
94
95 void f10(std::pair<ExplicitDefault, int>) {}
96
97 void f11(std::pair<ExplicitDefaultDefault, int>) {}
98
99 void test_arg_passing()
100 {
101 f6(v0); // { dg-error "could not convert" }
102 f6(v1);
103 f6({1,2}); // { dg-error "explicit" }
104 f6(std::pair<Explicit, Explicit>{});
105 f6(std::pair<int, int>{}); // { dg-error "could not convert" }
106 f7(v0);
107 f7(v6);
108 f7({1,2});
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>{});
115 }
116
117 struct MoveOnly
118 {
119 MoveOnly() = default;
120 MoveOnly(MoveOnly&&) {}
121 };
122
123 struct ExplicitMoveOnly
124 {
125 ExplicitMoveOnly() = default;
126 ExplicitMoveOnly(ExplicitMoveOnly&&) {}
127 explicit ExplicitMoveOnly(MoveOnly&&) {}
128 };
129
130 std::pair<int*, ExplicitMoveOnly> v14{0, MoveOnly{}};
131 std::pair<ExplicitMoveOnly, int*> v15{MoveOnly{}, 0};
132
133 std::pair<int*, ExplicitMoveOnly> v16 =
134 {0, MoveOnly{}}; // { dg-error "explicit" }
135 std::pair<ExplicitMoveOnly, int*> v17 =
136 {MoveOnly{}, 0}; // { dg-error "explicit" }