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