1 // RUN: %clang_cc1 -fsyntax-only -pedantic -verify %s
2 int* f(int) { return 0; }
3 float* f(float) { return 0; }
6 void test_f(int iv, float fv) {
11 int* g(int, float, int); // expected-note {{candidate function}}
12 float* g(int, int, int); // expected-note {{candidate function}}
13 double* g(int, float, float); // expected-note {{candidate function}}
14 char* g(int, float, ...); // expected-note {{candidate function}}
17 void test_g(int iv, float fv) {
18 int* ip1 = g(iv, fv, 0);
19 float* fp1 = g(iv, iv, 0);
20 double* dp1 = g(iv, fv, fv);
22 char* cp2 = g(0, 0, 0, iv, fv);
24 double* dp2 = g(0, fv, 1.5); // expected-error {{call to 'g' is ambiguous}}
30 void test_h(float fv, unsigned char cv) {
38 void test_i(short sv, int iv, long lv, unsigned char ucv) {
48 void test_j(int* ip) {
56 int* ip1 = k("foo"); // expected-warning{{conversion from string literal to 'char *' is deprecated}}
57 int* ip2 = k(("foo")); // expected-warning{{conversion from string literal to 'char *' is deprecated}}
58 double* dp1 = k(L"foo");
65 int* ip1 = l(L"foo"); // expected-warning{{conversion from string literal to 'wchar_t *' is deprecated}}
66 double* dp1 = l("foo");
83 int* ip2 = n("foo"); // expected-warning{{conversion from string literal to 'char *' is deprecated}}
92 PromotesToIntValue = -1
95 enum PromotesToUnsignedInt {
96 PromotesToUnsignedIntValue = __INT_MAX__ * 2U
100 double* o(unsigned int);
104 int* ip1 = o(PromotesToIntValue);
105 double* dp1 = o(PromotesToUnsignedIntValue);
112 int* ip = p((short)1);
113 double* dp = p(1.0f);
117 signed short int_bitfield : 5;
118 unsigned int uint_bitfield : 8;
121 int* bitfields(int, int);
122 float* bitfields(unsigned int, int);
124 void test_bitfield(Bits bits, int x) {
125 int* ip = bitfields(bits.int_bitfield, 0);
126 float* fp = bitfields(bits.uint_bitfield, 0u);
129 int* multiparm(long, int, long); // expected-note {{candidate function}}
130 float* multiparm(int, int, int); // expected-note {{candidate function}}
131 double* multiparm(int, int, short); // expected-note {{candidate function}}
133 void test_multiparm(long lv, short sv, int iv) {
134 int* ip1 = multiparm(lv, iv, lv);
135 int* ip2 = multiparm(lv, sv, lv);
136 float* fp1 = multiparm(iv, iv, iv);
137 float* fp2 = multiparm(sv, iv, iv);
138 double* dp1 = multiparm(sv, sv, sv);
139 double* dp2 = multiparm(iv, sv, sv);
140 multiparm(sv, sv, lv); // expected-error {{call to 'multiparm' is ambiguous}}
143 // Test overloading based on qualification vs. no qualification
145 int* quals1(int const * p);
146 char* quals1(int * p);
148 int* quals2(int const * const * pp);
149 char* quals2(int * * pp);
151 int* quals3(int const * * const * ppp);
152 char* quals3(int *** ppp);
154 void test_quals(int * p, int * * pp, int * * * ppp) {
155 char* q1 = quals1(p);
156 char* q2 = quals2(pp);
157 char* q3 = quals3(ppp);
160 // Test overloading based on qualification ranking (C++ 13.3.2)p3.
161 int* quals_rank1(int const * p);
162 float* quals_rank1(int const volatile *p);
163 char* quals_rank1(char*);
164 double* quals_rank1(const char*);
166 int* quals_rank2(int const * const * pp);
167 float* quals_rank2(int * const * pp);
169 void quals_rank3(int const * const * const volatile * p); // expected-note{{candidate function}}
170 void quals_rank3(int const * const volatile * const * p); // expected-note{{candidate function}}
172 void quals_rank3(int const *); // expected-note{{candidate function}}
173 void quals_rank3(int volatile *); // expected-note{{candidate function}}
175 void test_quals_ranking(int * p, int volatile *pq, int * * pp, int * * * ppp) {
176 int* q1 = quals_rank1(p);
177 float* q2 = quals_rank1(pq);
178 double* q3 = quals_rank1("string literal");
181 char* q4 = quals_rank1(a);
182 double* q5 = quals_rank1(ap);
184 float* q6 = quals_rank2(pp);
186 quals_rank3(ppp); // expected-error {{call to 'quals_rank3' is ambiguous}}
188 quals_rank3(p); // expected-error {{call to 'quals_rank3' is ambiguous}}
192 // Test overloading based on derived-to-base conversions
194 class B : public A { };
195 class C : public B { };
196 class D : public C { };
199 char* derived1(const A*);
200 float* derived1(void*);
206 float* derived3(const B*);
209 void test_derived(B* b, B const* bc, C* c, const C* cc, void* v, D* d) {
210 int* d1 = derived1(b);
211 char* d2 = derived1(bc);
212 int* d3 = derived1(c);
213 char* d4 = derived1(cc);
214 float* d5 = derived1(v);
216 float* d6 = derived2(b);
217 float* d7 = derived2(c);
219 char* d8 = derived3(d);
222 void derived4(C*); // expected-note{{candidate function not viable: cannot convert from base class pointer 'A *' to derived class pointer 'C *' for 1st argument}}
224 void test_base(A* a) {
225 derived4(a); // expected-error{{no matching function for call to 'derived4}}
228 // Test overloading of references.
229 // (FIXME: tests binding to determine candidate sets, not overload
230 // resolution per se).
232 float* intref(const int&);
235 float* ir1 = intref(5);
236 float* ir2 = intref(5.5); // expected-warning{{implicit conversion from 'double' to 'int' changes value from 5.5 to 5}}
239 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}}
241 void test_base(A& a) {
242 derived5(a); // expected-error{{no matching function for call to 'derived5}}
245 // Test reference binding vs. standard conversions.
246 int& bind_vs_conv(const double&);
247 float& bind_vs_conv(int);
249 void bind_vs_conv_test()
251 int& i1 = bind_vs_conv(1.0f);
252 float& f1 = bind_vs_conv((short)1);
255 // Test that cv-qualifiers get subsumed in the reference binding.
260 int& cvqual_subsume(X&); // expected-note{{candidate function}}
261 float& cvqual_subsume(const Y&); // expected-note{{candidate function}}
263 int& cvqual_subsume2(X&); // expected-note{{candidate function}}
264 float& cvqual_subsume2(volatile Y&); // expected-note{{candidate function}}
266 void cvqual_subsume_test(Z z) {
267 cvqual_subsume(z); // expected-error{{call to 'cvqual_subsume' is ambiguous}}
268 cvqual_subsume2(z); // expected-error{{call to 'cvqual_subsume2' is ambiguous}}
271 // Test overloading with cv-qualification differences in reference
273 int& cvqual_diff(X&);
274 float& cvqual_diff(const X&);
276 void cvqual_diff_test(X x, Z z) {
277 int& i1 = cvqual_diff(x);
278 int& i2 = cvqual_diff(z);
281 // Test overloading with derived-to-base differences in reference
287 float& db_rebind(Z&);
289 void db_rebind_test(Z2 z2) {
290 float& f1 = db_rebind(z2);
294 class opt : public string { };
309 float &a(void*, float);
316 // Tests the exact text used to note the candidates
318 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}}
319 void foo(int n, char N); // expected-note {{candidate function not viable: no known conversion from 'const char [6]' to 'char' for 2nd argument}}
320 void foo(int n, const char *s, int t); // expected-note {{candidate function not viable: requires 3 arguments, but 2 were provided}}
321 void foo(int n, const char *s, int t, ...); // expected-note {{candidate function not viable: requires at least 3 arguments, but 2 were provided}}
322 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}}
325 void foo(int n); // expected-note {{candidate function not viable: requires single argument 'n', but 2 arguments were provided}}
326 void foo(unsigned n = 10); // expected-note {{candidate function not viable: allows at most single argument 'n', but 2 arguments were provided}}
327 void bar(int n, int u = 0); // expected-note {{candidate function not viable: requires at least argument 'n', but no arguments were provided}}
328 void baz(int n = 0, int u = 0); // expected-note {{candidate function not viable: requires at most 2 arguments, but 3 were provided}}
331 foo(4, "hello"); //expected-error {{no matching function for call to 'foo'}}
332 bar(); //expected-error {{no matching function for call to 'bar'}}
333 baz(3, 4, 5); // expected-error {{no matching function for call to 'baz'}}
344 bool operator==(const QFixed &f, int i);
347 inline operator unsigned int () const;
349 inline bool operator==(const qrgb666 &v) const;
350 inline bool operator!=(const qrgb666 &v) const { return !(*this == v); }
359 void foo(Base *); // expected-note 2 {{cannot convert argument of incomplete type}}
360 void foo(Base &); // expected-note 2 {{cannot convert argument of incomplete type}}
362 void test(Incomplete *P) {
363 foo(P); // expected-error {{no matching function for call to 'foo'}}
364 foo(*P); // expected-error {{no matching function for call to 'foo'}}
368 namespace DerivedToBaseVsVoid {
384 static void foo(); // expected-note {{not viable}}
385 static void foo(int*); // expected-note {{not viable}}
386 static void foo(long*); // expected-note {{not viable}}
389 foo(a); // expected-error {{no matching function for call}}
394 namespace DerivedToBase {
409 operator const unsigned int & () const;
413 operator unsigned int & () const;
416 void f0(const bool &);
417 void f1(bool &); // expected-note 2{{not viable}}
419 void g(X0 x0, X1 x1) {
421 f1(x0); // expected-error{{no matching function for call}}
423 f1(x1); // expected-error{{no matching function for call}}
429 A(short); // expected-note{{candidate constructor}}
430 A(long); // expected-note{{candidate constructor}}
438 S()(0); // expected-error{{conversion from 'int' to 'PR6078::A' is ambiguous}}
443 struct String { String(char const*); };
445 void f(bool const volatile&);
448 void g() { int &r = f(""); }
462 void g(Y y) { f(y); }
467 class B : public A {};
469 int &foo(A *const d);
470 float &foo(const A *const d);
475 B const *const d2 = 0;
481 namespace NontrivialSubsequence {
487 operator const X0 *();
491 void foo( void const * );
498 // rdar://rdar8499524
499 namespace rdar8499524 {
511 namespace rdar9173984 {
512 template <typename T, unsigned long N> int &f(const T (&)[N]);
513 template <typename T> float &f(const T *);
524 void f(int * const&); // expected-note{{candidate function}}
525 void f(int const(&)[1]); // expected-note{{candidate function}}
529 f(n); // expected-error{{call to 'f' is ambiguous}}
533 namespace rdar9803316 {
542 namespace IncompleteArg {
543 // Ensure that overload resolution attempts to complete argument types when
545 template<typename T> struct S {
546 friend int f(const S&);
551 template<typename T> struct Op {
552 friend bool operator==(const Op &, const Op &);
557 // ... and not in other cases! Nothing here requires U<int()> to be complete.
558 // (Note that instantiating U<int()> will fail.)
559 template<typename T> struct U {
564 int operator()(const U<T> &);
566 template<typename T> U<T> &make();
568 int n = sizeof(c(make<int()>()));
572 void fun(int (*x)[10]); // expected-note{{candidate function not viable: 1st argument ('const int (*)[10]') would lose const qualifier}}
573 void g() { fun((const int(*)[10])0); } // expected-error{{no matching function for call to 'fun'}}
576 // DR1152: Take 'volatile' into account when handling reference bindings in
577 // overload resolution.
579 void f(const int &, ...);
580 void f(const volatile int &, int);
581 void g() { f(0, 0); }