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