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