Douglas Gregor | 8e9bebd | 2008-10-21 16:13:35 +0000 | [diff] [blame] | 1 | // RUN: clang -fsyntax-only -pedantic -verify %s |
| 2 | int* f(int); |
| 3 | float* f(float); |
| 4 | void f(); |
| 5 | |
| 6 | void test_f(int iv, float fv) { |
| 7 | float* fp = f(fv); |
| 8 | int* ip = f(iv); |
| 9 | } |
| 10 | |
| 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 }} |
| 15 | void g(); |
| 16 | |
| 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); |
| 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 | |
| 27 | double* h(double f); |
| 28 | int* h(int); |
| 29 | |
| 30 | void test_h(float fv, unsigned char cv) { |
| 31 | double* dp = h(fv); |
| 32 | int* ip = h(cv); |
| 33 | } |
| 34 | |
| 35 | int* i(int); |
| 36 | double* i(long); |
| 37 | |
| 38 | void 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 | |
| 45 | int* j(void*); |
| 46 | double* j(bool); |
| 47 | |
| 48 | void test_j(int* ip) { |
| 49 | int* ip1 = j(ip); |
| 50 | } |
| 51 | |
| 52 | int* k(char*); |
| 53 | double* k(bool); |
| 54 | |
| 55 | void test_k() { |
| 56 | int* ip1 = k("foo"); |
| 57 | double* dp1 = k(L"foo"); |
| 58 | } |
| 59 | |
| 60 | int* l(wchar_t*); |
| 61 | double* l(bool); |
| 62 | |
| 63 | void test_l() { |
| 64 | int* ip1 = l(L"foo"); |
| 65 | double* dp1 = l("foo"); |
| 66 | } |
| 67 | |
| 68 | int* m(const char*); |
| 69 | double* m(char*); |
| 70 | |
| 71 | void test_m() { |
| 72 | int* ip = m("foo"); |
| 73 | } |
| 74 | |
| 75 | int* n(char*); |
| 76 | double* n(void*); |
| 77 | |
| 78 | void 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 | |
| 87 | enum PromotesToInt { |
| 88 | PromotesToIntValue = 1 |
| 89 | }; |
| 90 | |
| 91 | enum PromotesToUnsignedInt { |
| 92 | PromotesToUnsignedIntValue = (unsigned int)-1 |
| 93 | }; |
| 94 | |
| 95 | int* o(int); |
| 96 | double* o(unsigned int); |
| 97 | float* o(long); |
| 98 | |
| 99 | void test_o() { |
| 100 | int* ip1 = o(PromotesToIntValue); |
| 101 | double* dp1 = o(PromotesToUnsignedIntValue); |
| 102 | } |
| 103 | |
| 104 | int* p(int); |
| 105 | double* p(double); |
| 106 | |
| 107 | void test_p() { |
| 108 | int* ip = p((short)1); |
| 109 | double* dp = p(1.0f); |
| 110 | } |
| 111 | |
| 112 | struct Bits { |
| 113 | signed short int_bitfield : 5; |
| 114 | unsigned int uint_bitfield : 8; |
| 115 | }; |
| 116 | |
| 117 | int* bitfields(int, int); |
| 118 | float* bitfields(unsigned int, int); |
| 119 | |
| 120 | void test_bitfield(Bits bits, int x) { |
| 121 | int* ip = bitfields(bits.int_bitfield, 0); |
| 122 | float* fp = bitfields(bits.uint_bitfield, 0u); |
| 123 | } |
| 124 | |
| 125 | int* multiparm(long, int, long); // expected-note {{ candidate function }} |
| 126 | float* multiparm(int, int, int); // expected-note {{ candidate function }} |
| 127 | double* multiparm(int, int, short); // expected-note {{ candidate function }} |
| 128 | |
| 129 | void 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 | } |
Douglas Gregor | 9b6e2d2 | 2008-10-22 00:38:21 +0000 | [diff] [blame^] | 138 | |
| 139 | // Test overloading based on qualification vs. no qualification |
| 140 | // conversion. |
| 141 | int* quals1(int const * p); |
| 142 | char* quals1(int * p); |
| 143 | |
| 144 | int* quals2(int const * const * pp); |
| 145 | char* quals2(int * * pp); |
| 146 | |
| 147 | int* quals3(int const * * const * ppp); |
| 148 | char* quals3(int *** ppp); |
| 149 | |
| 150 | void test_quals(int * p, int * * pp, int * * * ppp) { |
| 151 | char* q1 = quals1(p); |
| 152 | char* q2 = quals2(pp); |
| 153 | char* q3 = quals3(ppp); |
| 154 | } |
| 155 | |
| 156 | // Test overloading based on qualification ranking (C++ 13.3.2)p3. |
| 157 | int* quals_rank1(int const * p); |
| 158 | float* quals_rank1(int const volatile *p); |
| 159 | |
| 160 | int* quals_rank2(int const * const * pp); |
| 161 | float* quals_rank2(int * const * pp); |
| 162 | |
| 163 | void test_quals_ranking(int * p, int volatile *pq, int * * pp, int * * * ppp) { |
| 164 | // int* q1 = quals_rank1(p); |
| 165 | float* q2 = quals_rank1(pq); |
| 166 | } |