Daniel Dunbar | a572887 | 2009-12-15 20:14:24 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -pedantic -verify %s |
Douglas Gregor | 6fc17ff | 2008-10-29 15:10:40 +0000 | [diff] [blame] | 2 | int* f(int) { return 0; } |
| 3 | float* f(float) { return 0; } |
Douglas Gregor | 8e9bebd | 2008-10-21 16:13:35 +0000 | [diff] [blame] | 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() { |
Douglas Gregor | a9bff30 | 2010-02-28 18:30:25 +0000 | [diff] [blame] | 56 | int* ip1 = k("foo"); // expected-warning{{conversion from string literal to 'char *' is deprecated}} |
Douglas Gregor | 1984eb9 | 2010-06-22 23:47:37 +0000 | [diff] [blame] | 57 | int* ip2 = k(("foo")); // expected-warning{{conversion from string literal to 'char *' is deprecated}} |
Douglas Gregor | 8e9bebd | 2008-10-21 16:13:35 +0000 | [diff] [blame] | 58 | double* dp1 = k(L"foo"); |
| 59 | } |
| 60 | |
| 61 | int* l(wchar_t*); |
| 62 | double* l(bool); |
| 63 | |
| 64 | void test_l() { |
Douglas Gregor | a9bff30 | 2010-02-28 18:30:25 +0000 | [diff] [blame] | 65 | int* ip1 = l(L"foo"); // expected-warning{{conversion from string literal to 'wchar_t *' is deprecated}} |
Douglas Gregor | 8e9bebd | 2008-10-21 16:13:35 +0000 | [diff] [blame] | 66 | double* dp1 = l("foo"); |
| 67 | } |
| 68 | |
| 69 | int* m(const char*); |
| 70 | double* m(char*); |
| 71 | |
| 72 | void test_m() { |
| 73 | int* ip = m("foo"); |
| 74 | } |
| 75 | |
| 76 | int* n(char*); |
| 77 | double* n(void*); |
Douglas Gregor | 0f669f5 | 2008-11-26 23:33:36 +0000 | [diff] [blame] | 78 | class E; |
Douglas Gregor | 8e9bebd | 2008-10-21 16:13:35 +0000 | [diff] [blame] | 79 | |
Douglas Gregor | 0f669f5 | 2008-11-26 23:33:36 +0000 | [diff] [blame] | 80 | void test_n(E* e) { |
Douglas Gregor | 8e9bebd | 2008-10-21 16:13:35 +0000 | [diff] [blame] | 81 | char ca[7]; |
| 82 | int* ip1 = n(ca); |
Douglas Gregor | a9bff30 | 2010-02-28 18:30:25 +0000 | [diff] [blame] | 83 | int* ip2 = n("foo"); // expected-warning{{conversion from string literal to 'char *' is deprecated}} |
Douglas Gregor | 8e9bebd | 2008-10-21 16:13:35 +0000 | [diff] [blame] | 84 | |
| 85 | float fa[7]; |
| 86 | double* dp1 = n(fa); |
Douglas Gregor | 0f669f5 | 2008-11-26 23:33:36 +0000 | [diff] [blame] | 87 | |
| 88 | double* dp2 = n(e); |
Douglas Gregor | 8e9bebd | 2008-10-21 16:13:35 +0000 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | enum PromotesToInt { |
Douglas Gregor | c9467cf | 2008-12-12 02:00:36 +0000 | [diff] [blame] | 92 | PromotesToIntValue = -1 |
Douglas Gregor | 8e9bebd | 2008-10-21 16:13:35 +0000 | [diff] [blame] | 93 | }; |
| 94 | |
| 95 | enum PromotesToUnsignedInt { |
John McCall | 842aef8 | 2009-12-09 09:09:27 +0000 | [diff] [blame] | 96 | PromotesToUnsignedIntValue = __INT_MAX__ * 2U |
Douglas Gregor | 8e9bebd | 2008-10-21 16:13:35 +0000 | [diff] [blame] | 97 | }; |
| 98 | |
| 99 | int* o(int); |
| 100 | double* o(unsigned int); |
| 101 | float* o(long); |
| 102 | |
| 103 | void test_o() { |
| 104 | int* ip1 = o(PromotesToIntValue); |
| 105 | double* dp1 = o(PromotesToUnsignedIntValue); |
| 106 | } |
| 107 | |
| 108 | int* p(int); |
| 109 | double* p(double); |
| 110 | |
| 111 | void test_p() { |
| 112 | int* ip = p((short)1); |
| 113 | double* dp = p(1.0f); |
| 114 | } |
| 115 | |
| 116 | struct Bits { |
| 117 | signed short int_bitfield : 5; |
| 118 | unsigned int uint_bitfield : 8; |
| 119 | }; |
| 120 | |
| 121 | int* bitfields(int, int); |
| 122 | float* bitfields(unsigned int, int); |
| 123 | |
| 124 | void test_bitfield(Bits bits, int x) { |
| 125 | int* ip = bitfields(bits.int_bitfield, 0); |
| 126 | float* fp = bitfields(bits.uint_bitfield, 0u); |
| 127 | } |
| 128 | |
| 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 }} |
| 132 | |
| 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; candidates are: }} |
| 141 | } |
Douglas Gregor | 9b6e2d2 | 2008-10-22 00:38:21 +0000 | [diff] [blame] | 142 | |
| 143 | // Test overloading based on qualification vs. no qualification |
| 144 | // conversion. |
| 145 | int* quals1(int const * p); |
| 146 | char* quals1(int * p); |
| 147 | |
| 148 | int* quals2(int const * const * pp); |
| 149 | char* quals2(int * * pp); |
| 150 | |
| 151 | int* quals3(int const * * const * ppp); |
| 152 | char* quals3(int *** ppp); |
| 153 | |
| 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); |
| 158 | } |
| 159 | |
| 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); |
Douglas Gregor | 5737326 | 2008-10-22 14:17:15 +0000 | [diff] [blame] | 163 | char* quals_rank1(char*); |
| 164 | double* quals_rank1(const char*); |
Douglas Gregor | 9b6e2d2 | 2008-10-22 00:38:21 +0000 | [diff] [blame] | 165 | |
| 166 | int* quals_rank2(int const * const * pp); |
| 167 | float* quals_rank2(int * const * pp); |
| 168 | |
Douglas Gregor | 5737326 | 2008-10-22 14:17:15 +0000 | [diff] [blame] | 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}} |
| 171 | |
| 172 | void quals_rank3(int const *); // expected-note{{candidate function}} |
| 173 | void quals_rank3(int volatile *); // expected-note{{candidate function}} |
| 174 | |
Douglas Gregor | 9b6e2d2 | 2008-10-22 00:38:21 +0000 | [diff] [blame] | 175 | 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] | 176 | int* q1 = quals_rank1(p); |
Douglas Gregor | 9b6e2d2 | 2008-10-22 00:38:21 +0000 | [diff] [blame] | 177 | float* q2 = quals_rank1(pq); |
Douglas Gregor | 5737326 | 2008-10-22 14:17:15 +0000 | [diff] [blame] | 178 | double* q3 = quals_rank1("string literal"); |
| 179 | char a[17]; |
| 180 | const char* ap = a; |
| 181 | char* q4 = quals_rank1(a); |
| 182 | double* q5 = quals_rank1(ap); |
| 183 | |
| 184 | float* q6 = quals_rank2(pp); |
| 185 | |
| 186 | quals_rank3(ppp); // expected-error {{call to 'quals_rank3' is ambiguous; candidates are:}} |
| 187 | |
| 188 | quals_rank3(p); // expected-error {{call to 'quals_rank3' is ambiguous; candidates are:}} |
| 189 | quals_rank3(pq); |
Douglas Gregor | 9b6e2d2 | 2008-10-22 00:38:21 +0000 | [diff] [blame] | 190 | } |
Douglas Gregor | 5737326 | 2008-10-22 14:17:15 +0000 | [diff] [blame] | 191 | |
Douglas Gregor | bc0805a | 2008-10-23 00:40:37 +0000 | [diff] [blame] | 192 | // Test overloading based on derived-to-base conversions |
| 193 | class A { }; |
| 194 | class B : public A { }; |
| 195 | class C : public B { }; |
| 196 | class D : public C { }; |
| 197 | |
| 198 | int* derived1(A*); |
| 199 | char* derived1(const A*); |
| 200 | float* derived1(void*); |
| 201 | |
| 202 | int* derived2(A*); |
| 203 | float* derived2(B*); |
| 204 | |
| 205 | int* derived3(A*); |
| 206 | float* derived3(const B*); |
| 207 | char* derived3(C*); |
| 208 | |
| 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); |
| 215 | |
| 216 | float* d6 = derived2(b); |
| 217 | float* d7 = derived2(c); |
| 218 | |
| 219 | char* d8 = derived3(d); |
| 220 | } |
Douglas Gregor | 27c8dc0 | 2008-10-29 00:13:59 +0000 | [diff] [blame] | 221 | |
Douglas Gregor | 8578981 | 2010-06-30 23:01:39 +0000 | [diff] [blame] | 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}} |
| 223 | |
| 224 | void test_base(A* a) { |
| 225 | derived4(a); // expected-error{{no matching function for call to 'derived4}} |
| 226 | } |
| 227 | |
Douglas Gregor | 27c8dc0 | 2008-10-29 00:13:59 +0000 | [diff] [blame] | 228 | // Test overloading of references. |
| 229 | // (FIXME: tests binding to determine candidate sets, not overload |
| 230 | // resolution per se). |
| 231 | int* intref(int&); |
| 232 | float* intref(const int&); |
| 233 | |
| 234 | void intref_test() { |
| 235 | float* ir1 = intref(5); |
| 236 | float* ir2 = intref(5.5); |
| 237 | } |
Douglas Gregor | 15da57e | 2008-10-29 02:00:59 +0000 | [diff] [blame] | 238 | |
Douglas Gregor | 2f9d874 | 2010-07-01 02:14:45 +0000 | [diff] [blame] | 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}} |
| 240 | |
| 241 | void test_base(A& a) { |
| 242 | derived5(a); // expected-error{{no matching function for call to 'derived5}} |
| 243 | } |
| 244 | |
Douglas Gregor | 15da57e | 2008-10-29 02:00:59 +0000 | [diff] [blame] | 245 | // Test reference binding vs. standard conversions. |
| 246 | int& bind_vs_conv(const double&); |
| 247 | float& bind_vs_conv(int); |
| 248 | |
| 249 | void bind_vs_conv_test() |
| 250 | { |
| 251 | int& i1 = bind_vs_conv(1.0f); |
| 252 | float& f1 = bind_vs_conv((short)1); |
| 253 | } |
| 254 | |
| 255 | // Test that cv-qualifiers get subsumed in the reference binding. |
| 256 | struct X { }; |
| 257 | struct Y { }; |
| 258 | struct Z : X, Y { }; |
| 259 | |
| 260 | int& cvqual_subsume(X&); // expected-note{{candidate function}} |
| 261 | float& cvqual_subsume(const Y&); // expected-note{{candidate function}} |
| 262 | |
Douglas Gregor | 66821b5 | 2010-04-18 09:22:00 +0000 | [diff] [blame] | 263 | int& cvqual_subsume2(const X&); // expected-note{{candidate function}} |
| 264 | float& cvqual_subsume2(const volatile Y&); // expected-note{{candidate function}} |
Douglas Gregor | 15da57e | 2008-10-29 02:00:59 +0000 | [diff] [blame] | 265 | |
| 266 | Z get_Z(); |
| 267 | |
| 268 | void cvqual_subsume_test(Z z) { |
| 269 | cvqual_subsume(z); // expected-error{{call to 'cvqual_subsume' is ambiguous; candidates are:}} |
Douglas Gregor | 66821b5 | 2010-04-18 09:22:00 +0000 | [diff] [blame] | 270 | int& x = cvqual_subsume2(get_Z()); // expected-error{{call to 'cvqual_subsume2' is ambiguous; candidates are:}} |
Douglas Gregor | 15da57e | 2008-10-29 02:00:59 +0000 | [diff] [blame] | 271 | } |
Douglas Gregor | f70bdb9 | 2008-10-29 14:50:44 +0000 | [diff] [blame] | 272 | |
| 273 | // Test overloading with cv-qualification differences in reference |
| 274 | // binding. |
| 275 | int& cvqual_diff(X&); |
| 276 | float& cvqual_diff(const X&); |
| 277 | |
| 278 | void cvqual_diff_test(X x, Z z) { |
| 279 | int& i1 = cvqual_diff(x); |
| 280 | int& i2 = cvqual_diff(z); |
| 281 | } |
| 282 | |
| 283 | // Test overloading with derived-to-base differences in reference |
| 284 | // binding. |
| 285 | struct Z2 : Z { }; |
| 286 | |
| 287 | int& db_rebind(X&); |
| 288 | long& db_rebind(Y&); |
| 289 | float& db_rebind(Z&); |
| 290 | |
| 291 | void db_rebind_test(Z2 z2) { |
| 292 | float& f1 = db_rebind(z2); |
| 293 | } |
Douglas Gregor | b7a86f5 | 2009-11-06 01:02:41 +0000 | [diff] [blame] | 294 | |
| 295 | class string { }; |
| 296 | class opt : public string { }; |
| 297 | |
| 298 | struct SR { |
| 299 | SR(const string&); |
| 300 | }; |
| 301 | |
| 302 | void f(SR) { } |
| 303 | |
| 304 | void g(opt o) { |
| 305 | f(o); |
| 306 | } |
Douglas Gregor | 335b07a | 2009-12-13 21:29:20 +0000 | [diff] [blame] | 307 | |
| 308 | |
| 309 | namespace PR5756 { |
| 310 | int &a(void*, int); |
| 311 | float &a(void*, float); |
| 312 | void b() { |
| 313 | int &ir = a(0,0); |
| 314 | (void)ir; |
| 315 | } |
| 316 | } |
John McCall | 3c80f57 | 2010-01-12 02:15:36 +0000 | [diff] [blame] | 317 | |
| 318 | // Tests the exact text used to note the candidates |
| 319 | namespace test1 { |
Chris Lattner | 58f9e13 | 2010-09-05 00:04:01 +0000 | [diff] [blame] | 320 | 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}} |
| 321 | 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] | 322 | void foo(int n); // expected-note {{candidate function not viable: requires 1 argument, but 2 were provided}} |
| 323 | void foo(unsigned n = 10); // expected-note {{candidate function not viable: requires at most 1 argument, but 2 were provided}} |
| 324 | void foo(int n, const char *s, int t); // expected-note {{candidate function not viable: requires 3 arguments, but 2 were provided}} |
| 325 | void foo(int n, const char *s, int t, ...); // expected-note {{candidate function not viable: requires at least 3 arguments, but 2 were provided}} |
| 326 | 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] | 327 | |
| 328 | void test() { |
| 329 | foo(4, "hello"); //expected-error {{no matching function for call to 'foo'}} |
| 330 | } |
| 331 | } |
John McCall | adbb8f8 | 2010-01-13 09:16:55 +0000 | [diff] [blame] | 332 | |
John McCall | cefd3ad | 2010-01-13 22:30:33 +0000 | [diff] [blame] | 333 | // PR 6014 |
| 334 | namespace test2 { |
| 335 | struct QFixed { |
| 336 | QFixed(int i); |
| 337 | QFixed(long i); |
| 338 | }; |
| 339 | |
| 340 | bool operator==(const QFixed &f, int i); |
| 341 | |
| 342 | class qrgb666 { |
| 343 | inline operator unsigned int () const; |
| 344 | |
| 345 | inline bool operator==(const qrgb666 &v) const; |
| 346 | inline bool operator!=(const qrgb666 &v) const { return !(*this == v); } |
| 347 | }; |
| 348 | } |
John McCall | 258b203 | 2010-01-23 08:10:49 +0000 | [diff] [blame] | 349 | |
| 350 | // PR 6117 |
| 351 | namespace test3 { |
| 352 | struct Base {}; |
| 353 | struct Incomplete; |
| 354 | |
| 355 | void foo(Base *); // expected-note 2 {{cannot convert argument of incomplete type}} |
| 356 | void foo(Base &); // expected-note 2 {{cannot convert argument of incomplete type}} |
| 357 | |
| 358 | void test(Incomplete *P) { |
| 359 | foo(P); // expected-error {{no matching function for call to 'foo'}} |
| 360 | foo(*P); // expected-error {{no matching function for call to 'foo'}} |
| 361 | } |
| 362 | } |
Douglas Gregor | ad323a8 | 2010-01-27 03:51:04 +0000 | [diff] [blame] | 363 | |
| 364 | namespace DerivedToBaseVsVoid { |
| 365 | struct A { }; |
| 366 | struct B : A { }; |
| 367 | |
| 368 | float &f(void *); |
| 369 | int &f(const A*); |
| 370 | |
| 371 | void g(B *b) { |
| 372 | int &ir = f(b); |
| 373 | } |
| 374 | } |
John McCall | b1bdc62 | 2010-02-25 01:37:24 +0000 | [diff] [blame] | 375 | |
John McCall | 3a81337 | 2010-02-25 10:46:05 +0000 | [diff] [blame] | 376 | // PR 6398 + PR 6421 |
John McCall | b1bdc62 | 2010-02-25 01:37:24 +0000 | [diff] [blame] | 377 | namespace test4 { |
| 378 | class A; |
| 379 | class B { |
| 380 | static void foo(); // expected-note {{not viable}} |
| 381 | static void foo(int*); // expected-note {{not viable}} |
John McCall | 3a81337 | 2010-02-25 10:46:05 +0000 | [diff] [blame] | 382 | static void foo(long*); // expected-note {{not viable}} |
John McCall | b1bdc62 | 2010-02-25 01:37:24 +0000 | [diff] [blame] | 383 | |
| 384 | void bar(A *a) { |
| 385 | foo(a); // expected-error {{no matching function for call}} |
| 386 | } |
| 387 | }; |
| 388 | } |
Douglas Gregor | 9e23932 | 2010-02-25 19:01:05 +0000 | [diff] [blame] | 389 | |
| 390 | namespace DerivedToBase { |
| 391 | struct A { }; |
| 392 | struct B : A { }; |
| 393 | struct C : B { }; |
| 394 | |
| 395 | int &f0(const A&); |
| 396 | float &f0(B); |
| 397 | |
| 398 | void g() { |
| 399 | float &fr = f0(C()); |
| 400 | } |
| 401 | } |
Douglas Gregor | a1a9f03 | 2010-03-07 23:17:44 +0000 | [diff] [blame] | 402 | |
| 403 | namespace PR6483 { |
| 404 | struct X0 { |
| 405 | operator const unsigned int & () const; |
| 406 | }; |
| 407 | |
| 408 | struct X1 { |
| 409 | operator unsigned int & () const; |
| 410 | }; |
| 411 | |
| 412 | void f0(const bool &); |
| 413 | void f1(bool &); // expected-note 2{{not viable}} |
| 414 | |
| 415 | void g(X0 x0, X1 x1) { |
| 416 | f0(x0); |
| 417 | f1(x0); // expected-error{{no matching function for call}} |
| 418 | f0(x1); |
| 419 | f1(x1); // expected-error{{no matching function for call}} |
| 420 | } |
| 421 | } |
Douglas Gregor | aa0be17 | 2010-04-13 15:50:39 +0000 | [diff] [blame] | 422 | |
| 423 | namespace PR6078 { |
Douglas Gregor | d1a2722 | 2010-04-24 20:54:38 +0000 | [diff] [blame] | 424 | struct A { |
Douglas Gregor | aa0be17 | 2010-04-13 15:50:39 +0000 | [diff] [blame] | 425 | A(short); // expected-note{{candidate constructor}} |
| 426 | A(long); // expected-note{{candidate constructor}} |
| 427 | }; |
| 428 | struct S { |
| 429 | typedef void ft(A); |
| 430 | operator ft*(); |
| 431 | }; |
| 432 | |
| 433 | void f() { |
| 434 | S()(0); // expected-error{{conversion from 'int' to 'PR6078::A' is ambiguous}} |
| 435 | } |
| 436 | } |
Douglas Gregor | 66821b5 | 2010-04-18 09:22:00 +0000 | [diff] [blame] | 437 | |
| 438 | namespace PR6177 { |
| 439 | struct String { String(char const*); }; |
| 440 | |
Douglas Gregor | a41a8c5 | 2010-04-22 00:20:18 +0000 | [diff] [blame] | 441 | void f(bool const volatile&); // expected-note{{passing argument to parameter here}} |
Douglas Gregor | 66821b5 | 2010-04-18 09:22:00 +0000 | [diff] [blame] | 442 | void f(String); |
| 443 | |
Chris Lattner | 58f9e13 | 2010-09-05 00:04:01 +0000 | [diff] [blame] | 444 | void g() { f(""); } // expected-error{{volatile lvalue reference to type 'const volatile bool' cannot bind to a value of unrelated type 'const char [1]'}} |
Douglas Gregor | 66821b5 | 2010-04-18 09:22:00 +0000 | [diff] [blame] | 445 | } |
Douglas Gregor | ae65f4b | 2010-05-23 22:10:15 +0000 | [diff] [blame] | 446 | |
| 447 | namespace PR7095 { |
| 448 | struct X { }; |
| 449 | |
| 450 | struct Y { |
| 451 | operator const X*(); |
| 452 | |
| 453 | private: |
| 454 | operator X*(); |
| 455 | }; |
| 456 | |
| 457 | void f(const X *); |
| 458 | void g(Y y) { f(y); } |
| 459 | } |
Douglas Gregor | af7bea5 | 2010-05-25 15:31:05 +0000 | [diff] [blame] | 460 | |
| 461 | namespace PR7224 { |
| 462 | class A {}; |
| 463 | class B : public A {}; |
| 464 | |
| 465 | int &foo(A *const d); |
| 466 | float &foo(const A *const d); |
| 467 | |
| 468 | void bar() |
| 469 | { |
| 470 | B *const d = 0; |
| 471 | B const *const d2 = 0; |
| 472 | int &ir = foo(d); |
| 473 | float &fr = foo(d2); |
| 474 | } |
| 475 | } |
Douglas Gregor | 5a57efd | 2010-06-09 03:53:18 +0000 | [diff] [blame] | 476 | |
| 477 | namespace NontrivialSubsequence { |
| 478 | struct X0; |
| 479 | |
| 480 | class A { |
| 481 | operator X0 *(); |
| 482 | public: |
| 483 | operator const X0 *(); |
| 484 | }; |
| 485 | |
| 486 | A a; |
| 487 | void foo( void const * ); |
| 488 | |
| 489 | void g() { |
| 490 | foo(a); |
| 491 | } |
| 492 | } |
Argyrios Kyrtzidis | 25e7e16 | 2010-10-05 03:15:43 +0000 | [diff] [blame] | 493 | |
| 494 | // rdar://rdar8499524 |
| 495 | namespace rdar8499524 { |
| 496 | struct W {}; |
| 497 | struct S { |
| 498 | S(...); |
| 499 | }; |
| 500 | |
| 501 | void g(const S&); |
| 502 | void f() { |
| 503 | g(W()); |
| 504 | } |
| 505 | } |
Douglas Gregor | 4ae5b72 | 2011-06-05 06:15:20 +0000 | [diff] [blame] | 506 | |
| 507 | namespace rdar9173984 { |
| 508 | template <typename T, unsigned long N> int &f(const T (&)[N]); |
| 509 | template <typename T> float &f(const T *); |
| 510 | |
| 511 | void test() { |
| 512 | int arr[2] = {0, 0}; |
| 513 | int *arrp = arr; |
| 514 | int &ir = f(arr); |
| 515 | float &fr = f(arrp); |
| 516 | } |
| 517 | } |
| 518 | |
| 519 | namespace PR9507 { |
| 520 | void f(int * const&); // expected-note{{candidate function}} |
| 521 | void f(int const(&)[1]); // expected-note{{candidate function}} |
| 522 | |
| 523 | int main() { |
| 524 | int n[1]; |
| 525 | f(n); // expected-error{{call to 'f' is ambiguous}} |
| 526 | } |
| 527 | } |
Douglas Gregor | ee697e6 | 2011-10-13 18:10:35 +0000 | [diff] [blame] | 528 | |
| 529 | namespace rdar9803316 { |
| 530 | void foo(float); |
| 531 | int &foo(int); |
| 532 | |
| 533 | void bar() { |
| 534 | int &ir = (&foo)(0); |
| 535 | } |
| 536 | } |