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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
|
// RUN: %clang_cc1 -fsyntax-only -pedantic -verify %s
int* f(int) { return 0; }
float* f(float) { return 0; }
void f();
void test_f(int iv, float fv) {
float* fp = f(fv);
int* ip = f(iv);
}
int* g(int, float, int); // expected-note {{ candidate function }}
float* g(int, int, int); // expected-note {{ candidate function }}
double* g(int, float, float); // expected-note {{ candidate function }}
char* g(int, float, ...); // expected-note {{ candidate function }}
void g();
void test_g(int iv, float fv) {
int* ip1 = g(iv, fv, 0);
float* fp1 = g(iv, iv, 0);
double* dp1 = g(iv, fv, fv);
char* cp1 = g(0, 0);
char* cp2 = g(0, 0, 0, iv, fv);
double* dp2 = g(0, fv, 1.5); // expected-error {{ call to 'g' is ambiguous; candidates are: }}
}
double* h(double f);
int* h(int);
void test_h(float fv, unsigned char cv) {
double* dp = h(fv);
int* ip = h(cv);
}
int* i(int);
double* i(long);
void test_i(short sv, int iv, long lv, unsigned char ucv) {
int* ip1 = i(sv);
int* ip2 = i(iv);
int* ip3 = i(ucv);
double* dp1 = i(lv);
}
int* j(void*);
double* j(bool);
void test_j(int* ip) {
int* ip1 = j(ip);
}
int* k(char*);
double* k(bool);
void test_k() {
int* ip1 = k("foo"); // expected-warning{{conversion from string literal to 'char *' is deprecated}}
double* dp1 = k(L"foo");
}
int* l(wchar_t*);
double* l(bool);
void test_l() {
int* ip1 = l(L"foo"); // expected-warning{{conversion from string literal to 'wchar_t *' is deprecated}}
double* dp1 = l("foo");
}
int* m(const char*);
double* m(char*);
void test_m() {
int* ip = m("foo");
}
int* n(char*);
double* n(void*);
class E;
void test_n(E* e) {
char ca[7];
int* ip1 = n(ca);
int* ip2 = n("foo"); // expected-warning{{conversion from string literal to 'char *' is deprecated}}
float fa[7];
double* dp1 = n(fa);
double* dp2 = n(e);
}
enum PromotesToInt {
PromotesToIntValue = -1
};
enum PromotesToUnsignedInt {
PromotesToUnsignedIntValue = __INT_MAX__ * 2U
};
int* o(int);
double* o(unsigned int);
float* o(long);
void test_o() {
int* ip1 = o(PromotesToIntValue);
double* dp1 = o(PromotesToUnsignedIntValue);
}
int* p(int);
double* p(double);
void test_p() {
int* ip = p((short)1);
double* dp = p(1.0f);
}
struct Bits {
signed short int_bitfield : 5;
unsigned int uint_bitfield : 8;
};
int* bitfields(int, int);
float* bitfields(unsigned int, int);
void test_bitfield(Bits bits, int x) {
int* ip = bitfields(bits.int_bitfield, 0);
float* fp = bitfields(bits.uint_bitfield, 0u);
}
int* multiparm(long, int, long); // expected-note {{ candidate function }}
float* multiparm(int, int, int); // expected-note {{ candidate function }}
double* multiparm(int, int, short); // expected-note {{ candidate function }}
void test_multiparm(long lv, short sv, int iv) {
int* ip1 = multiparm(lv, iv, lv);
int* ip2 = multiparm(lv, sv, lv);
float* fp1 = multiparm(iv, iv, iv);
float* fp2 = multiparm(sv, iv, iv);
double* dp1 = multiparm(sv, sv, sv);
double* dp2 = multiparm(iv, sv, sv);
multiparm(sv, sv, lv); // expected-error {{ call to 'multiparm' is ambiguous; candidates are: }}
}
// Test overloading based on qualification vs. no qualification
// conversion.
int* quals1(int const * p);
char* quals1(int * p);
int* quals2(int const * const * pp);
char* quals2(int * * pp);
int* quals3(int const * * const * ppp);
char* quals3(int *** ppp);
void test_quals(int * p, int * * pp, int * * * ppp) {
char* q1 = quals1(p);
char* q2 = quals2(pp);
char* q3 = quals3(ppp);
}
// Test overloading based on qualification ranking (C++ 13.3.2)p3.
int* quals_rank1(int const * p);
float* quals_rank1(int const volatile *p);
char* quals_rank1(char*);
double* quals_rank1(const char*);
int* quals_rank2(int const * const * pp);
float* quals_rank2(int * const * pp);
void quals_rank3(int const * const * const volatile * p); // expected-note{{candidate function}}
void quals_rank3(int const * const volatile * const * p); // expected-note{{candidate function}}
void quals_rank3(int const *); // expected-note{{candidate function}}
void quals_rank3(int volatile *); // expected-note{{candidate function}}
void test_quals_ranking(int * p, int volatile *pq, int * * pp, int * * * ppp) {
int* q1 = quals_rank1(p);
float* q2 = quals_rank1(pq);
double* q3 = quals_rank1("string literal");
char a[17];
const char* ap = a;
char* q4 = quals_rank1(a);
double* q5 = quals_rank1(ap);
float* q6 = quals_rank2(pp);
quals_rank3(ppp); // expected-error {{call to 'quals_rank3' is ambiguous; candidates are:}}
quals_rank3(p); // expected-error {{call to 'quals_rank3' is ambiguous; candidates are:}}
quals_rank3(pq);
}
// Test overloading based on derived-to-base conversions
class A { };
class B : public A { };
class C : public B { };
class D : public C { };
int* derived1(A*);
char* derived1(const A*);
float* derived1(void*);
int* derived2(A*);
float* derived2(B*);
int* derived3(A*);
float* derived3(const B*);
char* derived3(C*);
void test_derived(B* b, B const* bc, C* c, const C* cc, void* v, D* d) {
int* d1 = derived1(b);
char* d2 = derived1(bc);
int* d3 = derived1(c);
char* d4 = derived1(cc);
float* d5 = derived1(v);
float* d6 = derived2(b);
float* d7 = derived2(c);
char* d8 = derived3(d);
}
// Test overloading of references.
// (FIXME: tests binding to determine candidate sets, not overload
// resolution per se).
int* intref(int&);
float* intref(const int&);
void intref_test() {
float* ir1 = intref(5);
float* ir2 = intref(5.5);
}
// Test reference binding vs. standard conversions.
int& bind_vs_conv(const double&);
float& bind_vs_conv(int);
void bind_vs_conv_test()
{
int& i1 = bind_vs_conv(1.0f);
float& f1 = bind_vs_conv((short)1);
}
// Test that cv-qualifiers get subsumed in the reference binding.
struct X { };
struct Y { };
struct Z : X, Y { };
int& cvqual_subsume(X&); // expected-note{{candidate function}}
float& cvqual_subsume(const Y&); // expected-note{{candidate function}}
int& cvqual_subsume2(const X&);
float& cvqual_subsume2(const volatile Y&);
Z get_Z();
void cvqual_subsume_test(Z z) {
cvqual_subsume(z); // expected-error{{call to 'cvqual_subsume' is ambiguous; candidates are:}}
int& x = cvqual_subsume2(get_Z()); // okay: only binds to the first one
}
// Test overloading with cv-qualification differences in reference
// binding.
int& cvqual_diff(X&);
float& cvqual_diff(const X&);
void cvqual_diff_test(X x, Z z) {
int& i1 = cvqual_diff(x);
int& i2 = cvqual_diff(z);
}
// Test overloading with derived-to-base differences in reference
// binding.
struct Z2 : Z { };
int& db_rebind(X&);
long& db_rebind(Y&);
float& db_rebind(Z&);
void db_rebind_test(Z2 z2) {
float& f1 = db_rebind(z2);
}
class string { };
class opt : public string { };
struct SR {
SR(const string&);
};
void f(SR) { }
void g(opt o) {
f(o);
}
namespace PR5756 {
int &a(void*, int);
float &a(void*, float);
void b() {
int &ir = a(0,0);
(void)ir;
}
}
// Tests the exact text used to note the candidates
namespace test1 {
template <class T> void foo(T t, unsigned N); // expected-note {{candidate function [with T = int] not viable: no known conversion from 'char const [6]' to 'unsigned int' for 2nd argument}}
void foo(int n, char N); // expected-note {{candidate function not viable: no known conversion from 'char const [6]' to 'char' for 2nd argument}}
void foo(int n); // expected-note {{candidate function not viable: requires 1 argument, but 2 were provided}}
void foo(unsigned n = 10); // expected-note {{candidate function not viable: requires at most 1 argument, but 2 were provided}}
void foo(int n, const char *s, int t); // expected-note {{candidate function not viable: requires 3 arguments, but 2 were provided}}
void foo(int n, const char *s, int t, ...); // expected-note {{candidate function not viable: requires at least 3 arguments, but 2 were provided}}
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}}
void test() {
foo(4, "hello"); //expected-error {{no matching function for call to 'foo'}}
}
}
// PR 6014
namespace test2 {
struct QFixed {
QFixed(int i);
QFixed(long i);
};
bool operator==(const QFixed &f, int i);
class qrgb666 {
inline operator unsigned int () const;
inline bool operator==(const qrgb666 &v) const;
inline bool operator!=(const qrgb666 &v) const { return !(*this == v); }
};
}
// PR 6117
namespace test3 {
struct Base {};
struct Incomplete;
void foo(Base *); // expected-note 2 {{cannot convert argument of incomplete type}}
void foo(Base &); // expected-note 2 {{cannot convert argument of incomplete type}}
void test(Incomplete *P) {
foo(P); // expected-error {{no matching function for call to 'foo'}}
foo(*P); // expected-error {{no matching function for call to 'foo'}}
}
}
namespace DerivedToBaseVsVoid {
struct A { };
struct B : A { };
float &f(void *);
int &f(const A*);
void g(B *b) {
int &ir = f(b);
}
}
// PR 6398 + PR 6421
namespace test4 {
class A;
class B {
static void foo(); // expected-note {{not viable}}
static void foo(int*); // expected-note {{not viable}}
static void foo(long*); // expected-note {{not viable}}
void bar(A *a) {
foo(a); // expected-error {{no matching function for call}}
}
};
}
namespace DerivedToBase {
struct A { };
struct B : A { };
struct C : B { };
int &f0(const A&);
float &f0(B);
void g() {
float &fr = f0(C());
}
}
namespace PR6483 {
struct X0 {
operator const unsigned int & () const;
};
struct X1 {
operator unsigned int & () const;
};
void f0(const bool &);
void f1(bool &); // expected-note 2{{not viable}}
void g(X0 x0, X1 x1) {
f0(x0);
f1(x0); // expected-error{{no matching function for call}}
f0(x1);
f1(x1); // expected-error{{no matching function for call}}
}
}
|