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