Douglas Gregor | d6fb7ef | 2008-12-18 19:37:40 +0000 | [diff] [blame] | 1 | // RUN: clang -fsyntax-only -verify %s |
Douglas Gregor | dda7889 | 2008-12-18 23:43:31 +0000 | [diff] [blame] | 2 | @interface Foo |
| 3 | @end |
| 4 | |
| 5 | @implementation Foo |
| 6 | |
| 7 | void func(id); |
| 8 | |
| 9 | + zone { |
| 10 | func(self); |
| 11 | return self; |
| 12 | } |
| 13 | |
Douglas Gregor | 7ca0976 | 2008-11-27 01:19:21 +0000 | [diff] [blame] | 14 | @protocol P0 |
| 15 | @end |
| 16 | |
| 17 | @protocol P1 |
| 18 | @end |
| 19 | |
| 20 | @interface A <P0> |
Douglas Gregor | cb7de52 | 2008-11-26 23:31:11 +0000 | [diff] [blame] | 21 | @end |
| 22 | |
| 23 | @interface B : A |
| 24 | @end |
| 25 | |
Douglas Gregor | 7ca0976 | 2008-11-27 01:19:21 +0000 | [diff] [blame] | 26 | @interface C <P1> |
| 27 | @end |
| 28 | |
Douglas Gregor | cb7de52 | 2008-11-26 23:31:11 +0000 | [diff] [blame] | 29 | int& f(A*); |
| 30 | float& f(B*); |
| 31 | void g(A*); |
| 32 | |
| 33 | int& h(A*); |
| 34 | float& h(id); |
| 35 | |
| 36 | void test(A* a, B* b, id val) { |
| 37 | int& i1 = f(a); |
| 38 | float& f1 = f(b); |
| 39 | float& f2 = f(val); |
| 40 | g(a); |
| 41 | g(b); |
| 42 | g(val); |
| 43 | int& i2 = h(a); |
| 44 | float& f3 = h(val); |
| 45 | // int& i3 = h(b); FIXME: we match GCC here, but shouldn't this work? |
| 46 | } |
| 47 | |
Douglas Gregor | 45920e8 | 2008-12-19 17:40:08 +0000 | [diff] [blame^] | 48 | void downcast_test(A* a) { |
| 49 | B* b = a; // expected-warning{{incompatible pointer types initializing 'B *', expected 'A *'}} |
| 50 | b = a; // expected-warning{{incompatible pointer types assigning 'B *', expected 'A *'}} |
| 51 | } |
| 52 | |
Douglas Gregor | cb7de52 | 2008-11-26 23:31:11 +0000 | [diff] [blame] | 53 | int& cv(A*); |
| 54 | float& cv(const A*); |
| 55 | int& cv2(void*); |
| 56 | float& cv2(const void*); |
| 57 | |
| 58 | void cv_test(A* a, B* b, const A* ac, const B* bc) { |
| 59 | int &i1 = cv(a); |
| 60 | int &i2 = cv(b); |
| 61 | float &f1 = cv(ac); |
| 62 | float &f2 = cv(bc); |
| 63 | int& i3 = cv2(a); |
| 64 | float& f3 = cv2(ac); |
| 65 | } |
Douglas Gregor | 7ca0976 | 2008-11-27 01:19:21 +0000 | [diff] [blame] | 66 | |
| 67 | |
| 68 | int& qualid(id<P0>); |
| 69 | float& qualid(id<P1>); // FIXME: GCC complains that this isn't an overload. Is it? |
| 70 | |
| 71 | void qualid_test(A *a, B *b, C *c) { |
| 72 | int& i1 = qualid(a); |
| 73 | int& i2 = qualid(b); |
| 74 | float& f1 = qualid(c); |
| 75 | } |