overload-call.cpp revision 8e9bebdea69c590dedfbf27374114cb76fe12fbd
1// RUN: clang -fsyntax-only -pedantic -verify %s 2int* f(int); 3float* f(float); 4void f(); 5 6void test_f(int iv, float fv) { 7 float* fp = f(fv); 8 int* ip = f(iv); 9} 10 11int* g(int, float, int); // expected-note {{ candidate function }} 12float* g(int, int, int); // expected-note {{ candidate function }} 13double* g(int, float, float); // expected-note {{ candidate function }} 14char* g(int, float, ...); // expected-note {{ candidate function }} 15void g(); 16 17void 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); 21 char* cp1 = g(0, 0); 22 char* cp2 = g(0, 0, 0, iv, fv); 23 24 double* dp2 = g(0, fv, 1.5); // expected-error {{ call to 'g' is ambiguous; candidates are: }} 25} 26 27double* h(double f); 28int* h(int); 29 30void test_h(float fv, unsigned char cv) { 31 double* dp = h(fv); 32 int* ip = h(cv); 33} 34 35int* i(int); 36double* i(long); 37 38void test_i(short sv, int iv, long lv, unsigned char ucv) { 39 int* ip1 = i(sv); 40 int* ip2 = i(iv); 41 int* ip3 = i(ucv); 42 double* dp1 = i(lv); 43} 44 45int* j(void*); 46double* j(bool); 47 48void test_j(int* ip) { 49 int* ip1 = j(ip); 50} 51 52int* k(char*); 53double* k(bool); 54 55void test_k() { 56 int* ip1 = k("foo"); 57 double* dp1 = k(L"foo"); 58} 59 60int* l(wchar_t*); 61double* l(bool); 62 63void test_l() { 64 int* ip1 = l(L"foo"); 65 double* dp1 = l("foo"); 66} 67 68int* m(const char*); 69double* m(char*); 70 71void test_m() { 72 int* ip = m("foo"); 73} 74 75int* n(char*); 76double* n(void*); 77 78void test_n() { 79 char ca[7]; 80 int* ip1 = n(ca); 81 int* ip2 = n("foo"); 82 83 float fa[7]; 84 double* dp1 = n(fa); 85} 86 87enum PromotesToInt { 88 PromotesToIntValue = 1 89}; 90 91enum PromotesToUnsignedInt { 92 PromotesToUnsignedIntValue = (unsigned int)-1 93}; 94 95int* o(int); 96double* o(unsigned int); 97float* o(long); 98 99void test_o() { 100 int* ip1 = o(PromotesToIntValue); 101 double* dp1 = o(PromotesToUnsignedIntValue); 102} 103 104int* p(int); 105double* p(double); 106 107void test_p() { 108 int* ip = p((short)1); 109 double* dp = p(1.0f); 110} 111 112struct Bits { 113 signed short int_bitfield : 5; 114 unsigned int uint_bitfield : 8; 115}; 116 117int* bitfields(int, int); 118float* bitfields(unsigned int, int); 119 120void test_bitfield(Bits bits, int x) { 121 int* ip = bitfields(bits.int_bitfield, 0); 122 float* fp = bitfields(bits.uint_bitfield, 0u); 123} 124 125int* multiparm(long, int, long); // expected-note {{ candidate function }} 126float* multiparm(int, int, int); // expected-note {{ candidate function }} 127double* multiparm(int, int, short); // expected-note {{ candidate function }} 128 129void test_multiparm(long lv, short sv, int iv) { 130 int* ip1 = multiparm(lv, iv, lv); 131 int* ip2 = multiparm(lv, sv, lv); 132 float* fp1 = multiparm(iv, iv, iv); 133 float* fp2 = multiparm(sv, iv, iv); 134 double* dp1 = multiparm(sv, sv, sv); 135 double* dp2 = multiparm(iv, sv, sv); 136 multiparm(sv, sv, lv); // expected-error {{ call to 'multiparm' is ambiguous; candidates are: }} 137} 138