]>
Commit | Line | Data |
---|---|---|
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 | ||
22 | struct Explicit | |
23 | { | |
24 | Explicit() = default; | |
25 | explicit Explicit(int) {} | |
26 | }; | |
27 | ||
610a7006 | 28 | struct ExplicitDefault |
29 | { | |
30 | explicit ExplicitDefault() {} | |
31 | }; | |
32 | ||
33 | struct ExplicitDefaultDefault | |
34 | { | |
35 | explicit ExplicitDefaultDefault() = default; | |
36 | }; | |
37 | ||
d3c64041 | 38 | std::pair<int, int> f1() {return {1,2};} |
39 | ||
529d9008 | 40 | std::pair<Explicit, Explicit> f2() {return {1,2};} // { dg-error "could not convert" } |
d3c64041 | 41 | |
42 | std::pair<long, long> f3() {return std::pair<int, int>{1,2};} | |
43 | ||
44 | std::pair<Explicit, Explicit> f4() | |
45 | { | |
46 | return std::pair<int, int>{1,2}; // { dg-error "could not convert" } | |
47 | } | |
48 | ||
49 | std::pair<long, long> f5() {return {1,2};} | |
50 | ||
51 | std::pair<int, int> v0{1,2}; | |
52 | ||
53 | std::pair<Explicit, Explicit> v1{1,2}; | |
54 | ||
529d9008 | 55 | std::pair<Explicit, Explicit> v2 = {1,2}; // { dg-error "could not convert" } |
d3c64041 | 56 | |
57 | std::pair<Explicit, Explicit> v3{std::pair<int,int>{1,2}}; | |
58 | ||
59 | std::pair<Explicit, Explicit> v4 = | |
60 | std::pair<int,int>{1,2}; // { dg-error "conversion" } | |
61 | ||
62 | std::pair<char *, char *> v5(0,0); | |
63 | ||
64 | std::pair<long, long> v6{1,2}; | |
65 | ||
66 | std::pair<long, long> v7 = {1,2}; | |
67 | ||
68 | std::pair<long, long> v8{std::pair<int,int>{1,2}}; | |
69 | ||
70 | std::pair<long, long> v9 = std::pair<int,int>{1,2}; | |
71 | ||
72 | std::pair<Explicit, Explicit> v10{v0}; | |
73 | ||
74 | std::pair<Explicit, Explicit> v11 = v0; // { dg-error "conversion" } | |
75 | ||
76 | std::pair<long, long> v12{v0}; | |
77 | ||
78 | std::pair<long, long> v13 = v0; | |
79 | ||
80 | void f6(std::pair<Explicit, Explicit>) {} | |
81 | ||
82 | void f7(std::pair<long, long>) {} | |
83 | ||
610a7006 | 84 | std::pair<ExplicitDefault, int> f8() |
85 | { | |
529d9008 | 86 | return {}; // { dg-error "could not convert" } |
610a7006 | 87 | } |
88 | ||
89 | std::pair<ExplicitDefaultDefault, int> f9() | |
90 | { | |
529d9008 | 91 | return {}; // { dg-error "could not convert" } |
610a7006 | 92 | } |
93 | ||
94 | void f10(std::pair<ExplicitDefault, int>) {} | |
95 | ||
96 | void f11(std::pair<ExplicitDefaultDefault, int>) {} | |
97 | ||
d3c64041 | 98 | void 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 | ||
116 | struct MoveOnly | |
117 | { | |
118 | MoveOnly() = default; | |
119 | MoveOnly(MoveOnly&&) {} | |
120 | }; | |
121 | ||
122 | struct ExplicitMoveOnly | |
123 | { | |
124 | ExplicitMoveOnly() = default; | |
125 | ExplicitMoveOnly(ExplicitMoveOnly&&) {} | |
126 | explicit ExplicitMoveOnly(MoveOnly&&) {} | |
127 | }; | |
128 | ||
129 | std::pair<int*, ExplicitMoveOnly> v14{0, MoveOnly{}}; | |
130 | std::pair<ExplicitMoveOnly, int*> v15{MoveOnly{}, 0}; | |
131 | ||
132 | std::pair<int*, ExplicitMoveOnly> v16 = | |
529d9008 | 133 | {0, MoveOnly{}}; // { dg-error "could not convert" } |
d3c64041 | 134 | std::pair<ExplicitMoveOnly, int*> v17 = |
529d9008 | 135 | {MoveOnly{}, 0}; // { dg-error "could not convert" } |