annotate clang/test/SemaCXX/overload-call.cpp @ 222:81f6424ef0e3 llvm-original

LLVM original branch
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Sun, 18 Jul 2021 22:10:01 +0900 (2021-07-18)
parents 1d019706d866
children c4bab56944e8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
150
anatofuz
parents:
diff changeset
1 // RUN: %clang_cc1 -triple %itanium_abi_triple -pedantic -verify %s
anatofuz
parents:
diff changeset
2 // RUN: %clang_cc1 -triple %itanium_abi_triple -pedantic -verify -std=c++98 %s
anatofuz
parents:
diff changeset
3 // RUN: %clang_cc1 -triple %itanium_abi_triple -pedantic -verify -std=c++11 %s
anatofuz
parents:
diff changeset
4
anatofuz
parents:
diff changeset
5 int* f(int) { return 0; }
anatofuz
parents:
diff changeset
6 float* f(float) { return 0; }
anatofuz
parents:
diff changeset
7 void f();
anatofuz
parents:
diff changeset
8
anatofuz
parents:
diff changeset
9 void test_f(int iv, float fv) {
anatofuz
parents:
diff changeset
10 float* fp = f(fv);
anatofuz
parents:
diff changeset
11 int* ip = f(iv);
anatofuz
parents:
diff changeset
12 }
anatofuz
parents:
diff changeset
13
anatofuz
parents:
diff changeset
14 int* g(int, float, int); // expected-note {{candidate function}}
anatofuz
parents:
diff changeset
15 float* g(int, int, int);
anatofuz
parents:
diff changeset
16 double* g(int, float, float); // expected-note {{candidate function}}
anatofuz
parents:
diff changeset
17 char* g(int, float, ...);
anatofuz
parents:
diff changeset
18 void g();
anatofuz
parents:
diff changeset
19
anatofuz
parents:
diff changeset
20 void test_g(int iv, float fv) {
anatofuz
parents:
diff changeset
21 int* ip1 = g(iv, fv, 0);
anatofuz
parents:
diff changeset
22 float* fp1 = g(iv, iv, 0);
anatofuz
parents:
diff changeset
23 double* dp1 = g(iv, fv, fv);
anatofuz
parents:
diff changeset
24 char* cp1 = g(0, 0);
anatofuz
parents:
diff changeset
25 char* cp2 = g(0, 0, 0, iv, fv);
anatofuz
parents:
diff changeset
26
anatofuz
parents:
diff changeset
27 double* dp2 = g(0, fv, 1.5); // expected-error {{call to 'g' is ambiguous}}
anatofuz
parents:
diff changeset
28 }
anatofuz
parents:
diff changeset
29
anatofuz
parents:
diff changeset
30 double* h(double f);
anatofuz
parents:
diff changeset
31 int* h(int);
anatofuz
parents:
diff changeset
32
anatofuz
parents:
diff changeset
33 void test_h(float fv, unsigned char cv) {
anatofuz
parents:
diff changeset
34 double* dp = h(fv);
anatofuz
parents:
diff changeset
35 int* ip = h(cv);
anatofuz
parents:
diff changeset
36 }
anatofuz
parents:
diff changeset
37
anatofuz
parents:
diff changeset
38 int* i(int);
anatofuz
parents:
diff changeset
39 double* i(long);
anatofuz
parents:
diff changeset
40
anatofuz
parents:
diff changeset
41 void test_i(short sv, int iv, long lv, unsigned char ucv) {
anatofuz
parents:
diff changeset
42 int* ip1 = i(sv);
anatofuz
parents:
diff changeset
43 int* ip2 = i(iv);
anatofuz
parents:
diff changeset
44 int* ip3 = i(ucv);
anatofuz
parents:
diff changeset
45 double* dp1 = i(lv);
anatofuz
parents:
diff changeset
46 }
anatofuz
parents:
diff changeset
47
anatofuz
parents:
diff changeset
48 int* j(void*);
anatofuz
parents:
diff changeset
49 double* j(bool);
anatofuz
parents:
diff changeset
50
anatofuz
parents:
diff changeset
51 void test_j(int* ip) {
anatofuz
parents:
diff changeset
52 int* ip1 = j(ip);
anatofuz
parents:
diff changeset
53 }
anatofuz
parents:
diff changeset
54
anatofuz
parents:
diff changeset
55 int* k(char*);
anatofuz
parents:
diff changeset
56 double* k(bool);
anatofuz
parents:
diff changeset
57
anatofuz
parents:
diff changeset
58 void test_k() {
anatofuz
parents:
diff changeset
59 int* ip1 = k("foo");
anatofuz
parents:
diff changeset
60 #if __cplusplus <= 199711L
anatofuz
parents:
diff changeset
61 // expected-warning@-2 {{conversion from string literal to 'char *' is deprecated}}
anatofuz
parents:
diff changeset
62 #else
anatofuz
parents:
diff changeset
63 // expected-error@-4 {{cannot initialize a variable of type 'int *' with an rvalue of type 'double *'}}
anatofuz
parents:
diff changeset
64 #endif
anatofuz
parents:
diff changeset
65
anatofuz
parents:
diff changeset
66 int* ip2 = k(("foo"));
anatofuz
parents:
diff changeset
67 #if __cplusplus <= 199711L
anatofuz
parents:
diff changeset
68 // expected-warning@-2 {{conversion from string literal to 'char *' is deprecated}}
anatofuz
parents:
diff changeset
69 #else
anatofuz
parents:
diff changeset
70 // expected-error@-4 {{cannot initialize a variable of type 'int *' with an rvalue of type 'double *'}}
anatofuz
parents:
diff changeset
71 #endif
anatofuz
parents:
diff changeset
72 double* dp1 = k(L"foo");
anatofuz
parents:
diff changeset
73 }
anatofuz
parents:
diff changeset
74
anatofuz
parents:
diff changeset
75 int* l(wchar_t*);
anatofuz
parents:
diff changeset
76 double* l(bool);
anatofuz
parents:
diff changeset
77
anatofuz
parents:
diff changeset
78 void test_l() {
anatofuz
parents:
diff changeset
79 int* ip1 = l(L"foo");
anatofuz
parents:
diff changeset
80 #if __cplusplus <= 199711L
anatofuz
parents:
diff changeset
81 // expected-warning@-2 {{conversion from string literal to 'wchar_t *' is deprecated}}
anatofuz
parents:
diff changeset
82 #else
anatofuz
parents:
diff changeset
83 // expected-error@-4 {{cannot initialize a variable of type 'int *' with an rvalue of type 'double *'}}
anatofuz
parents:
diff changeset
84 #endif
anatofuz
parents:
diff changeset
85 double* dp1 = l("foo");
anatofuz
parents:
diff changeset
86 }
anatofuz
parents:
diff changeset
87
anatofuz
parents:
diff changeset
88 int* m(const char*);
anatofuz
parents:
diff changeset
89 double* m(char*);
anatofuz
parents:
diff changeset
90
anatofuz
parents:
diff changeset
91 void test_m() {
anatofuz
parents:
diff changeset
92 int* ip = m("foo");
anatofuz
parents:
diff changeset
93 }
anatofuz
parents:
diff changeset
94
anatofuz
parents:
diff changeset
95 int* n(char*);
anatofuz
parents:
diff changeset
96 double* n(void*);
anatofuz
parents:
diff changeset
97 class E;
anatofuz
parents:
diff changeset
98
anatofuz
parents:
diff changeset
99 void test_n(E* e) {
anatofuz
parents:
diff changeset
100 char ca[7];
anatofuz
parents:
diff changeset
101 int* ip1 = n(ca);
anatofuz
parents:
diff changeset
102 int* ip2 = n("foo");
anatofuz
parents:
diff changeset
103 #if __cplusplus <= 199711L
anatofuz
parents:
diff changeset
104 // expected-warning@-2 {{conversion from string literal to 'char *' is deprecated}}
anatofuz
parents:
diff changeset
105 #else
anatofuz
parents:
diff changeset
106 // expected-warning@-4 {{ISO C++11 does not allow conversion from string literal to 'char *'}}
anatofuz
parents:
diff changeset
107 #endif
anatofuz
parents:
diff changeset
108 float fa[7];
anatofuz
parents:
diff changeset
109 double* dp1 = n(fa);
anatofuz
parents:
diff changeset
110
anatofuz
parents:
diff changeset
111 double* dp2 = n(e);
anatofuz
parents:
diff changeset
112 }
anatofuz
parents:
diff changeset
113
anatofuz
parents:
diff changeset
114 enum PromotesToInt {
anatofuz
parents:
diff changeset
115 PromotesToIntValue = -1
anatofuz
parents:
diff changeset
116 };
anatofuz
parents:
diff changeset
117
anatofuz
parents:
diff changeset
118 enum PromotesToUnsignedInt {
anatofuz
parents:
diff changeset
119 PromotesToUnsignedIntValue = __INT_MAX__ * 2U
anatofuz
parents:
diff changeset
120 };
anatofuz
parents:
diff changeset
121
anatofuz
parents:
diff changeset
122 int* o(int);
anatofuz
parents:
diff changeset
123 double* o(unsigned int);
anatofuz
parents:
diff changeset
124 float* o(long);
anatofuz
parents:
diff changeset
125
anatofuz
parents:
diff changeset
126 void test_o() {
anatofuz
parents:
diff changeset
127 int* ip1 = o(PromotesToIntValue);
anatofuz
parents:
diff changeset
128 double* dp1 = o(PromotesToUnsignedIntValue);
anatofuz
parents:
diff changeset
129 }
anatofuz
parents:
diff changeset
130
anatofuz
parents:
diff changeset
131 int* p(int);
anatofuz
parents:
diff changeset
132 double* p(double);
anatofuz
parents:
diff changeset
133
anatofuz
parents:
diff changeset
134 void test_p() {
anatofuz
parents:
diff changeset
135 int* ip = p((short)1);
anatofuz
parents:
diff changeset
136 double* dp = p(1.0f);
anatofuz
parents:
diff changeset
137 }
anatofuz
parents:
diff changeset
138
anatofuz
parents:
diff changeset
139 struct Bits {
anatofuz
parents:
diff changeset
140 signed short int_bitfield : 5;
anatofuz
parents:
diff changeset
141 unsigned int uint_bitfield : 8;
anatofuz
parents:
diff changeset
142 };
anatofuz
parents:
diff changeset
143
anatofuz
parents:
diff changeset
144 int* bitfields(int, int);
anatofuz
parents:
diff changeset
145 float* bitfields(unsigned int, int);
anatofuz
parents:
diff changeset
146
anatofuz
parents:
diff changeset
147 void test_bitfield(Bits bits, int x) {
anatofuz
parents:
diff changeset
148 int* ip = bitfields(bits.int_bitfield, 0);
anatofuz
parents:
diff changeset
149 float* fp = bitfields(bits.uint_bitfield, 0u);
anatofuz
parents:
diff changeset
150 }
anatofuz
parents:
diff changeset
151
anatofuz
parents:
diff changeset
152 int* multiparm(long, int, long); // expected-note {{candidate function}}
anatofuz
parents:
diff changeset
153 float* multiparm(int, int, int); // expected-note {{candidate function}}
anatofuz
parents:
diff changeset
154 double* multiparm(int, int, short); // expected-note {{candidate function}}
anatofuz
parents:
diff changeset
155
anatofuz
parents:
diff changeset
156 void test_multiparm(long lv, short sv, int iv) {
anatofuz
parents:
diff changeset
157 int* ip1 = multiparm(lv, iv, lv);
anatofuz
parents:
diff changeset
158 int* ip2 = multiparm(lv, sv, lv);
anatofuz
parents:
diff changeset
159 float* fp1 = multiparm(iv, iv, iv);
anatofuz
parents:
diff changeset
160 float* fp2 = multiparm(sv, iv, iv);
anatofuz
parents:
diff changeset
161 double* dp1 = multiparm(sv, sv, sv);
anatofuz
parents:
diff changeset
162 double* dp2 = multiparm(iv, sv, sv);
anatofuz
parents:
diff changeset
163 multiparm(sv, sv, lv); // expected-error {{call to 'multiparm' is ambiguous}}
anatofuz
parents:
diff changeset
164 }
anatofuz
parents:
diff changeset
165
anatofuz
parents:
diff changeset
166 // Test overloading based on qualification vs. no qualification
anatofuz
parents:
diff changeset
167 // conversion.
anatofuz
parents:
diff changeset
168 int* quals1(int const * p);
anatofuz
parents:
diff changeset
169 char* quals1(int * p);
anatofuz
parents:
diff changeset
170
anatofuz
parents:
diff changeset
171 int* quals2(int const * const * pp);
anatofuz
parents:
diff changeset
172 char* quals2(int * * pp);
anatofuz
parents:
diff changeset
173
anatofuz
parents:
diff changeset
174 int* quals3(int const * * const * ppp);
anatofuz
parents:
diff changeset
175 char* quals3(int *** ppp);
anatofuz
parents:
diff changeset
176
anatofuz
parents:
diff changeset
177 void test_quals(int * p, int * * pp, int * * * ppp) {
anatofuz
parents:
diff changeset
178 char* q1 = quals1(p);
anatofuz
parents:
diff changeset
179 char* q2 = quals2(pp);
anatofuz
parents:
diff changeset
180 char* q3 = quals3(ppp);
anatofuz
parents:
diff changeset
181 }
anatofuz
parents:
diff changeset
182
anatofuz
parents:
diff changeset
183 // Test overloading based on qualification ranking (C++ 13.3.2)p3.
anatofuz
parents:
diff changeset
184 int* quals_rank1(int const * p);
anatofuz
parents:
diff changeset
185 float* quals_rank1(int const volatile *p);
anatofuz
parents:
diff changeset
186 char* quals_rank1(char*);
anatofuz
parents:
diff changeset
187 double* quals_rank1(const char*);
anatofuz
parents:
diff changeset
188
anatofuz
parents:
diff changeset
189 int* quals_rank2(int const * const * pp);
anatofuz
parents:
diff changeset
190 float* quals_rank2(int * const * pp);
anatofuz
parents:
diff changeset
191
anatofuz
parents:
diff changeset
192 void quals_rank3(int const * const * const volatile * p); // expected-note{{candidate function}}
anatofuz
parents:
diff changeset
193 void quals_rank3(int const * const volatile * const * p); // expected-note{{candidate function}}
anatofuz
parents:
diff changeset
194
anatofuz
parents:
diff changeset
195 void quals_rank3(int const *); // expected-note{{candidate function}}
anatofuz
parents:
diff changeset
196 void quals_rank3(int volatile *); // expected-note{{candidate function}}
anatofuz
parents:
diff changeset
197
anatofuz
parents:
diff changeset
198 void test_quals_ranking(int * p, int volatile *pq, int * * pp, int * * * ppp) {
anatofuz
parents:
diff changeset
199 int* q1 = quals_rank1(p);
anatofuz
parents:
diff changeset
200 float* q2 = quals_rank1(pq);
anatofuz
parents:
diff changeset
201 double* q3 = quals_rank1("string literal");
anatofuz
parents:
diff changeset
202 char a[17];
anatofuz
parents:
diff changeset
203 const char* ap = a;
anatofuz
parents:
diff changeset
204 char* q4 = quals_rank1(a);
anatofuz
parents:
diff changeset
205 double* q5 = quals_rank1(ap);
anatofuz
parents:
diff changeset
206
anatofuz
parents:
diff changeset
207 float* q6 = quals_rank2(pp);
anatofuz
parents:
diff changeset
208
anatofuz
parents:
diff changeset
209 quals_rank3(ppp); // expected-error {{call to 'quals_rank3' is ambiguous}}
anatofuz
parents:
diff changeset
210
anatofuz
parents:
diff changeset
211 quals_rank3(p); // expected-error {{call to 'quals_rank3' is ambiguous}}
anatofuz
parents:
diff changeset
212 quals_rank3(pq);
anatofuz
parents:
diff changeset
213 }
anatofuz
parents:
diff changeset
214
anatofuz
parents:
diff changeset
215 // Test overloading based on derived-to-base conversions
anatofuz
parents:
diff changeset
216 class A { };
anatofuz
parents:
diff changeset
217 class B : public A { };
anatofuz
parents:
diff changeset
218 class C : public B { };
anatofuz
parents:
diff changeset
219 class D : public C { };
anatofuz
parents:
diff changeset
220
anatofuz
parents:
diff changeset
221 int* derived1(A*);
anatofuz
parents:
diff changeset
222 char* derived1(const A*);
anatofuz
parents:
diff changeset
223 float* derived1(void*);
anatofuz
parents:
diff changeset
224
anatofuz
parents:
diff changeset
225 int* derived2(A*);
anatofuz
parents:
diff changeset
226 float* derived2(B*);
anatofuz
parents:
diff changeset
227
anatofuz
parents:
diff changeset
228 int* derived3(A*);
anatofuz
parents:
diff changeset
229 float* derived3(const B*);
anatofuz
parents:
diff changeset
230 char* derived3(C*);
anatofuz
parents:
diff changeset
231
anatofuz
parents:
diff changeset
232 void test_derived(B* b, B const* bc, C* c, const C* cc, void* v, D* d) {
anatofuz
parents:
diff changeset
233 int* d1 = derived1(b);
anatofuz
parents:
diff changeset
234 char* d2 = derived1(bc);
anatofuz
parents:
diff changeset
235 int* d3 = derived1(c);
anatofuz
parents:
diff changeset
236 char* d4 = derived1(cc);
anatofuz
parents:
diff changeset
237 float* d5 = derived1(v);
anatofuz
parents:
diff changeset
238
anatofuz
parents:
diff changeset
239 float* d6 = derived2(b);
anatofuz
parents:
diff changeset
240 float* d7 = derived2(c);
anatofuz
parents:
diff changeset
241
anatofuz
parents:
diff changeset
242 char* d8 = derived3(d);
anatofuz
parents:
diff changeset
243 }
anatofuz
parents:
diff changeset
244
anatofuz
parents:
diff changeset
245 void derived4(C*); // expected-note{{candidate function not viable: cannot convert from base class pointer 'A *' to derived class pointer 'C *' for 1st argument}}
anatofuz
parents:
diff changeset
246
anatofuz
parents:
diff changeset
247 void test_base(A* a) {
anatofuz
parents:
diff changeset
248 derived4(a); // expected-error{{no matching function for call to 'derived4}}
anatofuz
parents:
diff changeset
249 }
anatofuz
parents:
diff changeset
250
anatofuz
parents:
diff changeset
251 // Test overloading of references.
anatofuz
parents:
diff changeset
252 // (FIXME: tests binding to determine candidate sets, not overload
anatofuz
parents:
diff changeset
253 // resolution per se).
anatofuz
parents:
diff changeset
254 int* intref(int&);
anatofuz
parents:
diff changeset
255 float* intref(const int&);
anatofuz
parents:
diff changeset
256
anatofuz
parents:
diff changeset
257 void intref_test() {
anatofuz
parents:
diff changeset
258 float* ir1 = intref(5);
anatofuz
parents:
diff changeset
259 float* ir2 = intref(5.5); // expected-warning{{implicit conversion from 'double' to 'int' changes value from 5.5 to 5}}
anatofuz
parents:
diff changeset
260 }
anatofuz
parents:
diff changeset
261
anatofuz
parents:
diff changeset
262 void derived5(C&); // expected-note{{candidate function not viable: cannot bind base class object of type 'A' to derived class reference 'C &' for 1st argument}}
anatofuz
parents:
diff changeset
263
anatofuz
parents:
diff changeset
264 void test_base(A& a) {
anatofuz
parents:
diff changeset
265 derived5(a); // expected-error{{no matching function for call to 'derived5}}
anatofuz
parents:
diff changeset
266 }
anatofuz
parents:
diff changeset
267
anatofuz
parents:
diff changeset
268 // Test reference binding vs. standard conversions.
anatofuz
parents:
diff changeset
269 int& bind_vs_conv(const double&);
anatofuz
parents:
diff changeset
270 float& bind_vs_conv(int);
anatofuz
parents:
diff changeset
271
anatofuz
parents:
diff changeset
272 void bind_vs_conv_test()
anatofuz
parents:
diff changeset
273 {
anatofuz
parents:
diff changeset
274 int& i1 = bind_vs_conv(1.0f);
anatofuz
parents:
diff changeset
275 float& f1 = bind_vs_conv((short)1);
anatofuz
parents:
diff changeset
276 }
anatofuz
parents:
diff changeset
277
anatofuz
parents:
diff changeset
278 // Test that cv-qualifiers get subsumed in the reference binding.
anatofuz
parents:
diff changeset
279 struct X { };
anatofuz
parents:
diff changeset
280 struct Y { };
anatofuz
parents:
diff changeset
281 struct Z : X, Y { };
anatofuz
parents:
diff changeset
282
anatofuz
parents:
diff changeset
283 int& cvqual_subsume(X&); // expected-note{{candidate function}}
anatofuz
parents:
diff changeset
284 float& cvqual_subsume(const Y&); // expected-note{{candidate function}}
anatofuz
parents:
diff changeset
285
anatofuz
parents:
diff changeset
286 int& cvqual_subsume2(X&); // expected-note{{candidate function}}
anatofuz
parents:
diff changeset
287 float& cvqual_subsume2(volatile Y&); // expected-note{{candidate function}}
anatofuz
parents:
diff changeset
288
anatofuz
parents:
diff changeset
289 void cvqual_subsume_test(Z z) {
anatofuz
parents:
diff changeset
290 cvqual_subsume(z); // expected-error{{call to 'cvqual_subsume' is ambiguous}}
anatofuz
parents:
diff changeset
291 cvqual_subsume2(z); // expected-error{{call to 'cvqual_subsume2' is ambiguous}}
anatofuz
parents:
diff changeset
292 }
anatofuz
parents:
diff changeset
293
anatofuz
parents:
diff changeset
294 // Test overloading with cv-qualification differences in reference
anatofuz
parents:
diff changeset
295 // binding.
anatofuz
parents:
diff changeset
296 int& cvqual_diff(X&);
anatofuz
parents:
diff changeset
297 float& cvqual_diff(const X&);
anatofuz
parents:
diff changeset
298
anatofuz
parents:
diff changeset
299 void cvqual_diff_test(X x, Z z) {
anatofuz
parents:
diff changeset
300 int& i1 = cvqual_diff(x);
anatofuz
parents:
diff changeset
301 int& i2 = cvqual_diff(z);
anatofuz
parents:
diff changeset
302 }
anatofuz
parents:
diff changeset
303
anatofuz
parents:
diff changeset
304 // Test overloading with derived-to-base differences in reference
anatofuz
parents:
diff changeset
305 // binding.
anatofuz
parents:
diff changeset
306 struct Z2 : Z { };
anatofuz
parents:
diff changeset
307
anatofuz
parents:
diff changeset
308 int& db_rebind(X&);
anatofuz
parents:
diff changeset
309 long& db_rebind(Y&);
anatofuz
parents:
diff changeset
310 float& db_rebind(Z&);
anatofuz
parents:
diff changeset
311
anatofuz
parents:
diff changeset
312 void db_rebind_test(Z2 z2) {
anatofuz
parents:
diff changeset
313 float& f1 = db_rebind(z2);
anatofuz
parents:
diff changeset
314 }
anatofuz
parents:
diff changeset
315
anatofuz
parents:
diff changeset
316 class string { };
anatofuz
parents:
diff changeset
317 class opt : public string { };
anatofuz
parents:
diff changeset
318
anatofuz
parents:
diff changeset
319 struct SR {
anatofuz
parents:
diff changeset
320 SR(const string&);
anatofuz
parents:
diff changeset
321 };
anatofuz
parents:
diff changeset
322
anatofuz
parents:
diff changeset
323 void f(SR) { }
anatofuz
parents:
diff changeset
324
anatofuz
parents:
diff changeset
325 void g(opt o) {
anatofuz
parents:
diff changeset
326 f(o);
anatofuz
parents:
diff changeset
327 }
anatofuz
parents:
diff changeset
328
anatofuz
parents:
diff changeset
329
anatofuz
parents:
diff changeset
330 namespace PR5756 {
anatofuz
parents:
diff changeset
331 int &a(void*, int);
anatofuz
parents:
diff changeset
332 float &a(void*, float);
anatofuz
parents:
diff changeset
333 void b() {
anatofuz
parents:
diff changeset
334 int &ir = a(0,0);
anatofuz
parents:
diff changeset
335 (void)ir;
anatofuz
parents:
diff changeset
336 }
anatofuz
parents:
diff changeset
337 }
anatofuz
parents:
diff changeset
338
anatofuz
parents:
diff changeset
339 // Tests the exact text used to note the candidates
anatofuz
parents:
diff changeset
340 namespace test1 {
anatofuz
parents:
diff changeset
341 template <class T>
anatofuz
parents:
diff changeset
342 void foo(T t, unsigned N); // expected-note {{candidate function template not viable: no known conversion from 'const char [6]' to 'unsigned int' for 2nd argument}}
anatofuz
parents:
diff changeset
343 void foo(int n, char N); // expected-note {{candidate function not viable: no known conversion from 'const char [6]' to 'char' for 2nd argument}}
anatofuz
parents:
diff changeset
344 void foo(int n, const char *s, int t); // expected-note {{candidate function not viable: requires 3 arguments, but 2 were provided}}
anatofuz
parents:
diff changeset
345 void foo(int n, const char *s, int t, ...); // expected-note {{candidate function not viable: requires at least 3 arguments, but 2 were provided}}
anatofuz
parents:
diff changeset
346 void foo(int n, const char *s, int t, int u = 0); // expected-note {{candidate function not viable: requires at least 3 arguments, but 2 were provided}}
anatofuz
parents:
diff changeset
347
anatofuz
parents:
diff changeset
348 // PR 11857
anatofuz
parents:
diff changeset
349 void foo(int n); // expected-note {{candidate function not viable: requires single argument 'n', but 2 arguments were provided}}
anatofuz
parents:
diff changeset
350 void foo(unsigned n = 10); // expected-note {{candidate function not viable: allows at most single argument 'n', but 2 arguments were provided}}
anatofuz
parents:
diff changeset
351 void bar(int n, int u = 0); // expected-note {{candidate function not viable: requires at least argument 'n', but no arguments were provided}}
anatofuz
parents:
diff changeset
352 void baz(int n = 0, int u = 0); // expected-note {{candidate function not viable: requires at most 2 arguments, but 3 were provided}}
anatofuz
parents:
diff changeset
353
anatofuz
parents:
diff changeset
354 void test() {
anatofuz
parents:
diff changeset
355 foo(4, "hello"); //expected-error {{no matching function for call to 'foo'}}
anatofuz
parents:
diff changeset
356 bar(); //expected-error {{no matching function for call to 'bar'}}
anatofuz
parents:
diff changeset
357 baz(3, 4, 5); // expected-error {{no matching function for call to 'baz'}}
anatofuz
parents:
diff changeset
358 }
anatofuz
parents:
diff changeset
359 }
anatofuz
parents:
diff changeset
360
anatofuz
parents:
diff changeset
361 // PR 6014
anatofuz
parents:
diff changeset
362 namespace test2 {
anatofuz
parents:
diff changeset
363 struct QFixed {
anatofuz
parents:
diff changeset
364 QFixed(int i);
anatofuz
parents:
diff changeset
365 QFixed(long i);
anatofuz
parents:
diff changeset
366 };
anatofuz
parents:
diff changeset
367
anatofuz
parents:
diff changeset
368 bool operator==(const QFixed &f, int i);
anatofuz
parents:
diff changeset
369
anatofuz
parents:
diff changeset
370 class qrgb666 {
anatofuz
parents:
diff changeset
371 inline operator unsigned int () const;
anatofuz
parents:
diff changeset
372
anatofuz
parents:
diff changeset
373 inline bool operator==(const qrgb666 &v) const;
anatofuz
parents:
diff changeset
374 inline bool operator!=(const qrgb666 &v) const { return !(*this == v); }
anatofuz
parents:
diff changeset
375 };
anatofuz
parents:
diff changeset
376 }
anatofuz
parents:
diff changeset
377
anatofuz
parents:
diff changeset
378 // PR 6117
anatofuz
parents:
diff changeset
379 namespace IncompleteConversion {
anatofuz
parents:
diff changeset
380 struct Complete {};
anatofuz
parents:
diff changeset
381 struct Incomplete;
anatofuz
parents:
diff changeset
382
anatofuz
parents:
diff changeset
383 void completeFunction(Complete *); // expected-note 2 {{cannot convert argument of incomplete type}}
anatofuz
parents:
diff changeset
384 void completeFunction(Complete &); // expected-note 2 {{cannot convert argument of incomplete type}}
anatofuz
parents:
diff changeset
385
anatofuz
parents:
diff changeset
386 void testTypeConversion(Incomplete *P) {
anatofuz
parents:
diff changeset
387 completeFunction(P); // expected-error {{no matching function for call to 'completeFunction'}}
anatofuz
parents:
diff changeset
388 completeFunction(*P); // expected-error {{no matching function for call to 'completeFunction'}}
anatofuz
parents:
diff changeset
389 }
anatofuz
parents:
diff changeset
390
anatofuz
parents:
diff changeset
391 void incompletePointerFunction(Incomplete *); // expected-note {{candidate function not viable: cannot convert argument of incomplete type 'IncompleteConversion::Incomplete' to 'IncompleteConversion::Incomplete *' for 1st argument; take the address of the argument with &}}
anatofuz
parents:
diff changeset
392 void incompleteReferenceFunction(Incomplete &); // expected-note {{candidate function not viable: cannot convert argument of incomplete type 'IncompleteConversion::Incomplete *' to 'IncompleteConversion::Incomplete &' for 1st argument; dereference the argument with *}}
anatofuz
parents:
diff changeset
393
anatofuz
parents:
diff changeset
394 void testPointerReferenceConversion(Incomplete &reference, Incomplete *pointer) {
anatofuz
parents:
diff changeset
395 incompletePointerFunction(reference); // expected-error {{no matching function for call to 'incompletePointerFunction'}}
anatofuz
parents:
diff changeset
396 incompleteReferenceFunction(pointer); // expected-error {{no matching function for call to 'incompleteReferenceFunction'}}
anatofuz
parents:
diff changeset
397 }
anatofuz
parents:
diff changeset
398 }
anatofuz
parents:
diff changeset
399
anatofuz
parents:
diff changeset
400 namespace DerivedToBaseVsVoid {
anatofuz
parents:
diff changeset
401 struct A { };
anatofuz
parents:
diff changeset
402 struct B : A { };
anatofuz
parents:
diff changeset
403
anatofuz
parents:
diff changeset
404 float &f(void *);
anatofuz
parents:
diff changeset
405 int &f(const A*);
anatofuz
parents:
diff changeset
406
anatofuz
parents:
diff changeset
407 void g(B *b) {
anatofuz
parents:
diff changeset
408 int &ir = f(b);
anatofuz
parents:
diff changeset
409 }
anatofuz
parents:
diff changeset
410 }
anatofuz
parents:
diff changeset
411
anatofuz
parents:
diff changeset
412 // PR 6398 + PR 6421
anatofuz
parents:
diff changeset
413 namespace test4 {
anatofuz
parents:
diff changeset
414 class A;
anatofuz
parents:
diff changeset
415 class B {
anatofuz
parents:
diff changeset
416 static void foo(); // expected-note {{not viable}}
anatofuz
parents:
diff changeset
417 static void foo(int*); // expected-note {{not viable}}
anatofuz
parents:
diff changeset
418 static void foo(long*); // expected-note {{not viable}}
anatofuz
parents:
diff changeset
419
anatofuz
parents:
diff changeset
420 void bar(A *a) {
anatofuz
parents:
diff changeset
421 foo(a); // expected-error {{no matching function for call}}
anatofuz
parents:
diff changeset
422 }
anatofuz
parents:
diff changeset
423 };
anatofuz
parents:
diff changeset
424 }
anatofuz
parents:
diff changeset
425
anatofuz
parents:
diff changeset
426 namespace DerivedToBase {
anatofuz
parents:
diff changeset
427 struct A { };
anatofuz
parents:
diff changeset
428 struct B : A { };
anatofuz
parents:
diff changeset
429 struct C : B { };
anatofuz
parents:
diff changeset
430
anatofuz
parents:
diff changeset
431 int &f0(const A&);
anatofuz
parents:
diff changeset
432 float &f0(B);
anatofuz
parents:
diff changeset
433
anatofuz
parents:
diff changeset
434 void g() {
anatofuz
parents:
diff changeset
435 float &fr = f0(C());
anatofuz
parents:
diff changeset
436 }
anatofuz
parents:
diff changeset
437 }
anatofuz
parents:
diff changeset
438
anatofuz
parents:
diff changeset
439 namespace PR6483 {
anatofuz
parents:
diff changeset
440 struct X0 {
anatofuz
parents:
diff changeset
441 operator const unsigned int & () const;
anatofuz
parents:
diff changeset
442 };
anatofuz
parents:
diff changeset
443
anatofuz
parents:
diff changeset
444 struct X1 {
anatofuz
parents:
diff changeset
445 operator unsigned int & () const;
anatofuz
parents:
diff changeset
446 };
anatofuz
parents:
diff changeset
447
anatofuz
parents:
diff changeset
448 void f0(const bool &);
anatofuz
parents:
diff changeset
449 void f1(bool &); // expected-note 2{{not viable}}
anatofuz
parents:
diff changeset
450
anatofuz
parents:
diff changeset
451 void g(X0 x0, X1 x1) {
anatofuz
parents:
diff changeset
452 f0(x0);
anatofuz
parents:
diff changeset
453 f1(x0); // expected-error{{no matching function for call}}
anatofuz
parents:
diff changeset
454 f0(x1);
anatofuz
parents:
diff changeset
455 f1(x1); // expected-error{{no matching function for call}}
anatofuz
parents:
diff changeset
456 }
anatofuz
parents:
diff changeset
457 }
anatofuz
parents:
diff changeset
458
anatofuz
parents:
diff changeset
459 namespace PR6078 {
anatofuz
parents:
diff changeset
460 struct A {
anatofuz
parents:
diff changeset
461 A(short); // expected-note{{candidate constructor}}
anatofuz
parents:
diff changeset
462 A(long); // expected-note{{candidate constructor}}
anatofuz
parents:
diff changeset
463 };
anatofuz
parents:
diff changeset
464 struct S {
anatofuz
parents:
diff changeset
465 typedef void ft(A);
anatofuz
parents:
diff changeset
466 operator ft*();
anatofuz
parents:
diff changeset
467 };
anatofuz
parents:
diff changeset
468
anatofuz
parents:
diff changeset
469 void f() {
anatofuz
parents:
diff changeset
470 S()(0); // expected-error{{conversion from 'int' to 'PR6078::A' is ambiguous}}
anatofuz
parents:
diff changeset
471 }
anatofuz
parents:
diff changeset
472 }
anatofuz
parents:
diff changeset
473
anatofuz
parents:
diff changeset
474 namespace PR6177 {
anatofuz
parents:
diff changeset
475 struct String { String(char const*); };
anatofuz
parents:
diff changeset
476
anatofuz
parents:
diff changeset
477 void f(bool const volatile&);
anatofuz
parents:
diff changeset
478 int &f(String);
anatofuz
parents:
diff changeset
479
anatofuz
parents:
diff changeset
480 void g() { int &r = f(""); }
anatofuz
parents:
diff changeset
481 }
anatofuz
parents:
diff changeset
482
anatofuz
parents:
diff changeset
483 namespace PR7095 {
anatofuz
parents:
diff changeset
484 struct X { };
anatofuz
parents:
diff changeset
485
anatofuz
parents:
diff changeset
486 struct Y {
anatofuz
parents:
diff changeset
487 operator const X*();
anatofuz
parents:
diff changeset
488
anatofuz
parents:
diff changeset
489 private:
anatofuz
parents:
diff changeset
490 operator X*();
anatofuz
parents:
diff changeset
491 };
anatofuz
parents:
diff changeset
492
anatofuz
parents:
diff changeset
493 void f(const X *);
anatofuz
parents:
diff changeset
494 void g(Y y) { f(y); }
anatofuz
parents:
diff changeset
495 }
anatofuz
parents:
diff changeset
496
anatofuz
parents:
diff changeset
497 namespace PR7224 {
anatofuz
parents:
diff changeset
498 class A {};
anatofuz
parents:
diff changeset
499 class B : public A {};
anatofuz
parents:
diff changeset
500
anatofuz
parents:
diff changeset
501 int &foo(A *const d);
anatofuz
parents:
diff changeset
502 float &foo(const A *const d);
anatofuz
parents:
diff changeset
503
anatofuz
parents:
diff changeset
504 void bar()
anatofuz
parents:
diff changeset
505 {
anatofuz
parents:
diff changeset
506 B *const d = 0;
anatofuz
parents:
diff changeset
507 B const *const d2 = 0;
anatofuz
parents:
diff changeset
508 int &ir = foo(d);
anatofuz
parents:
diff changeset
509 float &fr = foo(d2);
anatofuz
parents:
diff changeset
510 }
anatofuz
parents:
diff changeset
511 }
anatofuz
parents:
diff changeset
512
anatofuz
parents:
diff changeset
513 namespace NontrivialSubsequence {
anatofuz
parents:
diff changeset
514 struct X0;
anatofuz
parents:
diff changeset
515
anatofuz
parents:
diff changeset
516 class A {
anatofuz
parents:
diff changeset
517 operator X0 *();
anatofuz
parents:
diff changeset
518 public:
anatofuz
parents:
diff changeset
519 operator const X0 *();
anatofuz
parents:
diff changeset
520 };
anatofuz
parents:
diff changeset
521
anatofuz
parents:
diff changeset
522 A a;
anatofuz
parents:
diff changeset
523 void foo( void const * );
anatofuz
parents:
diff changeset
524
anatofuz
parents:
diff changeset
525 void g() {
anatofuz
parents:
diff changeset
526 foo(a);
anatofuz
parents:
diff changeset
527 }
anatofuz
parents:
diff changeset
528 }
anatofuz
parents:
diff changeset
529
anatofuz
parents:
diff changeset
530 // rdar://rdar8499524
anatofuz
parents:
diff changeset
531 namespace rdar8499524 {
anatofuz
parents:
diff changeset
532 struct W {};
anatofuz
parents:
diff changeset
533 struct S {
anatofuz
parents:
diff changeset
534 S(...);
anatofuz
parents:
diff changeset
535 };
anatofuz
parents:
diff changeset
536
anatofuz
parents:
diff changeset
537 void g(const S&);
anatofuz
parents:
diff changeset
538 void f() {
anatofuz
parents:
diff changeset
539 g(W());
anatofuz
parents:
diff changeset
540 }
anatofuz
parents:
diff changeset
541 }
anatofuz
parents:
diff changeset
542
anatofuz
parents:
diff changeset
543 namespace rdar9173984 {
anatofuz
parents:
diff changeset
544 template <typename T, unsigned long N> int &f(const T (&)[N]);
anatofuz
parents:
diff changeset
545 template <typename T> float &f(const T *);
anatofuz
parents:
diff changeset
546
anatofuz
parents:
diff changeset
547 void test() {
anatofuz
parents:
diff changeset
548 int arr[2] = {0, 0};
anatofuz
parents:
diff changeset
549 int *arrp = arr;
anatofuz
parents:
diff changeset
550 int &ir = f(arr);
anatofuz
parents:
diff changeset
551 float &fr = f(arrp);
anatofuz
parents:
diff changeset
552 }
anatofuz
parents:
diff changeset
553 }
anatofuz
parents:
diff changeset
554
anatofuz
parents:
diff changeset
555 namespace PR9507 {
anatofuz
parents:
diff changeset
556 void f(int * const&); // expected-note{{candidate function}}
anatofuz
parents:
diff changeset
557 void f(int const(&)[1]); // expected-note{{candidate function}}
anatofuz
parents:
diff changeset
558
anatofuz
parents:
diff changeset
559 int main() {
anatofuz
parents:
diff changeset
560 int n[1];
anatofuz
parents:
diff changeset
561 f(n); // expected-error{{call to 'f' is ambiguous}}
anatofuz
parents:
diff changeset
562 }
anatofuz
parents:
diff changeset
563 }
anatofuz
parents:
diff changeset
564
anatofuz
parents:
diff changeset
565 namespace rdar9803316 {
anatofuz
parents:
diff changeset
566 void foo(float);
anatofuz
parents:
diff changeset
567 int &foo(int);
anatofuz
parents:
diff changeset
568
anatofuz
parents:
diff changeset
569 void bar() {
anatofuz
parents:
diff changeset
570 int &ir = (&foo)(0);
anatofuz
parents:
diff changeset
571 }
anatofuz
parents:
diff changeset
572 }
anatofuz
parents:
diff changeset
573
anatofuz
parents:
diff changeset
574 namespace IncompleteArg {
anatofuz
parents:
diff changeset
575 // Ensure that overload resolution attempts to complete argument types when
anatofuz
parents:
diff changeset
576 // performing ADL.
anatofuz
parents:
diff changeset
577 template<typename T> struct S {
anatofuz
parents:
diff changeset
578 friend int f(const S&);
anatofuz
parents:
diff changeset
579 };
anatofuz
parents:
diff changeset
580 extern S<int> s;
anatofuz
parents:
diff changeset
581 int k = f(s);
anatofuz
parents:
diff changeset
582
anatofuz
parents:
diff changeset
583 template<typename T> struct Op {
anatofuz
parents:
diff changeset
584 friend bool operator==(const Op &, const Op &);
anatofuz
parents:
diff changeset
585 };
anatofuz
parents:
diff changeset
586 extern Op<char> op;
anatofuz
parents:
diff changeset
587 bool b = op == op;
anatofuz
parents:
diff changeset
588
anatofuz
parents:
diff changeset
589 // ... and not in other cases! Nothing here requires U<int()> to be complete.
anatofuz
parents:
diff changeset
590 // (Note that instantiating U<int()> will fail.)
anatofuz
parents:
diff changeset
591 template<typename T> struct U {
anatofuz
parents:
diff changeset
592 T t;
anatofuz
parents:
diff changeset
593 };
anatofuz
parents:
diff changeset
594 struct Consumer {
anatofuz
parents:
diff changeset
595 template<typename T>
anatofuz
parents:
diff changeset
596 int operator()(const U<T> &);
anatofuz
parents:
diff changeset
597 };
anatofuz
parents:
diff changeset
598 template<typename T> U<T> &make();
anatofuz
parents:
diff changeset
599 Consumer c;
anatofuz
parents:
diff changeset
600 int n = sizeof(c(make<int()>()));
anatofuz
parents:
diff changeset
601 }
anatofuz
parents:
diff changeset
602
anatofuz
parents:
diff changeset
603 namespace PR12142 {
anatofuz
parents:
diff changeset
604 void fun(int (*x)[10]); // expected-note{{candidate function not viable: 1st argument ('const int (*)[10]') would lose const qualifier}}
anatofuz
parents:
diff changeset
605 void g() { fun((const int(*)[10])0); } // expected-error{{no matching function for call to 'fun'}}
anatofuz
parents:
diff changeset
606 }
anatofuz
parents:
diff changeset
607
anatofuz
parents:
diff changeset
608 // DR1152: Take 'volatile' into account when handling reference bindings in
anatofuz
parents:
diff changeset
609 // overload resolution.
anatofuz
parents:
diff changeset
610 namespace PR12931 {
anatofuz
parents:
diff changeset
611 void f(const int &, ...);
anatofuz
parents:
diff changeset
612 void f(const volatile int &, int);
anatofuz
parents:
diff changeset
613 void g() { f(0, 0); }
anatofuz
parents:
diff changeset
614 }
anatofuz
parents:
diff changeset
615
anatofuz
parents:
diff changeset
616 void test5() {
anatofuz
parents:
diff changeset
617 struct {
anatofuz
parents:
diff changeset
618 typedef void F1(int);
anatofuz
parents:
diff changeset
619 typedef void F2(double);
anatofuz
parents:
diff changeset
620 operator F1*(); // expected-note{{conversion candidate}}
anatofuz
parents:
diff changeset
621 operator F2*(); // expected-note{{conversion candidate}}
anatofuz
parents:
diff changeset
622 } callable;
anatofuz
parents:
diff changeset
623 callable(); // expected-error{{no matching function for call}}
anatofuz
parents:
diff changeset
624 }
anatofuz
parents:
diff changeset
625
anatofuz
parents:
diff changeset
626 namespace PR20218 {
anatofuz
parents:
diff changeset
627 void f(void (*const &)()); // expected-note 2{{candidate}}
anatofuz
parents:
diff changeset
628 void f(void (&&)()) = delete; // expected-note 2{{candidate}}
anatofuz
parents:
diff changeset
629 #if __cplusplus <= 199711L
anatofuz
parents:
diff changeset
630 // expected-warning@-2 {{rvalue references are a C++11 extension}}
anatofuz
parents:
diff changeset
631 // expected-warning@-3 {{deleted function definitions are a C++11 extension}}
anatofuz
parents:
diff changeset
632 #endif
anatofuz
parents:
diff changeset
633 void g(void (&&)()) = delete; // expected-note 2{{candidate}}
anatofuz
parents:
diff changeset
634 #if __cplusplus <= 199711L
anatofuz
parents:
diff changeset
635 // expected-warning@-2 {{rvalue references are a C++11 extension}}
anatofuz
parents:
diff changeset
636 // expected-warning@-3 {{deleted function definitions are a C++11 extension}}
anatofuz
parents:
diff changeset
637 #endif
anatofuz
parents:
diff changeset
638 void g(void (*const &)()); // expected-note 2{{candidate}}
anatofuz
parents:
diff changeset
639
anatofuz
parents:
diff changeset
640 void x();
anatofuz
parents:
diff changeset
641 typedef void (&fr)();
anatofuz
parents:
diff changeset
642 struct Y { operator fr(); } y;
anatofuz
parents:
diff changeset
643
anatofuz
parents:
diff changeset
644 void h() {
anatofuz
parents:
diff changeset
645 f(x); // expected-error {{ambiguous}}
anatofuz
parents:
diff changeset
646 g(x); // expected-error {{ambiguous}}
anatofuz
parents:
diff changeset
647 f(y); // expected-error {{ambiguous}}
anatofuz
parents:
diff changeset
648 g(y); // expected-error {{ambiguous}}
anatofuz
parents:
diff changeset
649 }
anatofuz
parents:
diff changeset
650 }
anatofuz
parents:
diff changeset
651
anatofuz
parents:
diff changeset
652 namespace StringLiteralToCharAmbiguity {
anatofuz
parents:
diff changeset
653 void f(char *, int);
anatofuz
parents:
diff changeset
654 void f(const char *, unsigned);
anatofuz
parents:
diff changeset
655 void g() { f("foo", 0); }
anatofuz
parents:
diff changeset
656 #if __cplusplus <= 199711L
anatofuz
parents:
diff changeset
657 // expected-error@-2 {{call to 'f' is ambiguous}}
anatofuz
parents:
diff changeset
658 // expected-note@-5 {{candidate function}}
anatofuz
parents:
diff changeset
659 // expected-note@-5 {{candidate function}}
anatofuz
parents:
diff changeset
660 #endif
anatofuz
parents:
diff changeset
661 }
anatofuz
parents:
diff changeset
662
anatofuz
parents:
diff changeset
663 namespace ProduceNotesAfterSFINAEFailure {
anatofuz
parents:
diff changeset
664 struct A {
anatofuz
parents:
diff changeset
665 template<typename T, typename U = typename T::x> A(T); // expected-warning 0-1{{extension}}
anatofuz
parents:
diff changeset
666 };
anatofuz
parents:
diff changeset
667 void f(void*, A); // expected-note {{candidate function not viable}}
anatofuz
parents:
diff changeset
668 void g() { f(1, 2); } // expected-error {{no matching function}}
anatofuz
parents:
diff changeset
669 }
anatofuz
parents:
diff changeset
670
anatofuz
parents:
diff changeset
671 namespace PR19808 {
anatofuz
parents:
diff changeset
672 struct B {
anatofuz
parents:
diff changeset
673 int i;
anatofuz
parents:
diff changeset
674 void bar();
anatofuz
parents:
diff changeset
675 };
anatofuz
parents:
diff changeset
676 struct D : public B{};
anatofuz
parents:
diff changeset
677
anatofuz
parents:
diff changeset
678 void f(bool);
anatofuz
parents:
diff changeset
679 void f(int D::*);
anatofuz
parents:
diff changeset
680 void f(void (D::*)());
anatofuz
parents:
diff changeset
681
anatofuz
parents:
diff changeset
682 void Usage() {
anatofuz
parents:
diff changeset
683 int B::*pmem;
anatofuz
parents:
diff changeset
684 void (B::*pmf)();
anatofuz
parents:
diff changeset
685
anatofuz
parents:
diff changeset
686 // These should not be ambiguous.
anatofuz
parents:
diff changeset
687 f(pmem);
anatofuz
parents:
diff changeset
688 f(pmf);
anatofuz
parents:
diff changeset
689 }
anatofuz
parents:
diff changeset
690 }