1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
// { dg-do compile }
// { dg-options "-std=gnu++11" }
// Copyright (C) 2015 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
#include <utility>
struct Explicit
{
Explicit() = default;
explicit Explicit(int) {}
};
std::pair<int, int> f1() {return {1,2};}
std::pair<Explicit, Explicit> f2() {return {1,2};} // { dg-error "explicit" }
std::pair<long, long> f3() {return std::pair<int, int>{1,2};}
std::pair<Explicit, Explicit> f4()
{
return std::pair<int, int>{1,2}; // { dg-error "could not convert" }
}
std::pair<long, long> f5() {return {1,2};}
std::pair<int, int> v0{1,2};
std::pair<Explicit, Explicit> v1{1,2};
std::pair<Explicit, Explicit> v2 = {1,2}; // { dg-error "explicit" }
std::pair<Explicit, Explicit> v3{std::pair<int,int>{1,2}};
std::pair<Explicit, Explicit> v4 =
std::pair<int,int>{1,2}; // { dg-error "conversion" }
std::pair<char *, char *> v5(0,0);
std::pair<long, long> v6{1,2};
std::pair<long, long> v7 = {1,2};
std::pair<long, long> v8{std::pair<int,int>{1,2}};
std::pair<long, long> v9 = std::pair<int,int>{1,2};
std::pair<Explicit, Explicit> v10{v0};
std::pair<Explicit, Explicit> v11 = v0; // { dg-error "conversion" }
std::pair<long, long> v12{v0};
std::pair<long, long> v13 = v0;
void f6(std::pair<Explicit, Explicit>) {}
void f7(std::pair<long, long>) {}
void test_arg_passing()
{
f6(v0); // { dg-error "could not convert" }
f6(v1);
f6({1,2}); // { dg-error "explicit" }
f6(std::pair<Explicit, Explicit>{});
f6(std::pair<int, int>{}); // { dg-error "could not convert" }
f7(v0);
f7(v6);
f7({1,2});
f7(std::pair<int, int>{});
f7(std::pair<long, long>{});
}
struct MoveOnly
{
MoveOnly() = default;
MoveOnly(MoveOnly&&) {}
};
struct ExplicitMoveOnly
{
ExplicitMoveOnly() = default;
ExplicitMoveOnly(ExplicitMoveOnly&&) {}
explicit ExplicitMoveOnly(MoveOnly&&) {}
};
std::pair<int*, ExplicitMoveOnly> v14{0, MoveOnly{}};
std::pair<ExplicitMoveOnly, int*> v15{MoveOnly{}, 0};
std::pair<int*, ExplicitMoveOnly> v16 =
{0, MoveOnly{}}; // { dg-error "explicit" }
std::pair<ExplicitMoveOnly, int*> v17 =
{MoveOnly{}, 0}; // { dg-error "explicit" }
|