]> 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
be58e01d 1// { dg-do compile { target c++11 } }
d3c64041 2
fbd26352 3// Copyright (C) 2015-2019 Free Software Foundation, Inc.
d3c64041 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
610a7006 28struct ExplicitDefault
29{
30 explicit ExplicitDefault() {}
31};
32
33struct ExplicitDefaultDefault
34{
35 explicit ExplicitDefaultDefault() = default;
36};
37
d3c64041 38std::pair<int, int> f1() {return {1,2};}
39
529d9008 40std::pair<Explicit, Explicit> f2() {return {1,2};} // { dg-error "could not convert" }
d3c64041 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
529d9008 55std::pair<Explicit, Explicit> v2 = {1,2}; // { dg-error "could not convert" }
d3c64041 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
610a7006 84std::pair<ExplicitDefault, int> f8()
85{
529d9008 86 return {}; // { dg-error "could not convert" }
610a7006 87}
88
89std::pair<ExplicitDefaultDefault, int> f9()
90{
529d9008 91 return {}; // { dg-error "could not convert" }
610a7006 92}
93
94void f10(std::pair<ExplicitDefault, int>) {}
95
96void f11(std::pair<ExplicitDefaultDefault, int>) {}
97
d3c64041 98void test_arg_passing()
99{
100 f6(v0); // { dg-error "could not convert" }
101 f6(v1);
529d9008 102 f6({1,2}); // { dg-error "could not convert" }
d3c64041 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>{});
529d9008 110 f10({}); // { dg-error "could not convert" }
111 f11({}); // { dg-error "could not convert" }
610a7006 112 f10(std::pair<ExplicitDefault, int>{});
113 f11(std::pair<ExplicitDefaultDefault, int>{});
d3c64041 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
129std::pair<int*, ExplicitMoveOnly> v14{0, MoveOnly{}};
130std::pair<ExplicitMoveOnly, int*> v15{MoveOnly{}, 0};
131
132std::pair<int*, ExplicitMoveOnly> v16 =
529d9008 133 {0, MoveOnly{}}; // { dg-error "could not convert" }
d3c64041 134std::pair<ExplicitMoveOnly, int*> v17 =
529d9008 135 {MoveOnly{}, 0}; // { dg-error "could not convert" }