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 | } |
Douglas Gregor | a46969d | 2008-12-19 19:16:37 +0000 | [diff] [blame] | 13 | @end |
Douglas Gregor | dda7889 | 2008-12-18 23:43:31 +0000 | [diff] [blame] | 14 | |
Douglas Gregor | 7ca0976 | 2008-11-27 01:19:21 +0000 | [diff] [blame] | 15 | @protocol P0 |
| 16 | @end |
| 17 | |
| 18 | @protocol P1 |
| 19 | @end |
| 20 | |
| 21 | @interface A <P0> |
Douglas Gregor | cb7de52 | 2008-11-26 23:31:11 +0000 | [diff] [blame] | 22 | @end |
| 23 | |
| 24 | @interface B : A |
| 25 | @end |
| 26 | |
Douglas Gregor | 7ca0976 | 2008-11-27 01:19:21 +0000 | [diff] [blame] | 27 | @interface C <P1> |
| 28 | @end |
| 29 | |
Douglas Gregor | cb7de52 | 2008-11-26 23:31:11 +0000 | [diff] [blame] | 30 | int& f(A*); |
| 31 | float& f(B*); |
| 32 | void g(A*); |
| 33 | |
| 34 | int& h(A*); |
| 35 | float& h(id); |
| 36 | |
| 37 | void test(A* a, B* b, id val) { |
| 38 | int& i1 = f(a); |
| 39 | float& f1 = f(b); |
| 40 | float& f2 = f(val); |
| 41 | g(a); |
| 42 | g(b); |
| 43 | g(val); |
| 44 | int& i2 = h(a); |
| 45 | float& f3 = h(val); |
| 46 | // int& i3 = h(b); FIXME: we match GCC here, but shouldn't this work? |
| 47 | } |
| 48 | |
Douglas Gregor | c788751 | 2008-12-19 19:13:09 +0000 | [diff] [blame] | 49 | void downcast_test(A* a, A** ap) { |
Douglas Gregor | 45920e8 | 2008-12-19 17:40:08 +0000 | [diff] [blame] | 50 | B* b = a; // expected-warning{{incompatible pointer types initializing 'B *', expected 'A *'}} |
| 51 | b = a; // expected-warning{{incompatible pointer types assigning 'B *', expected 'A *'}} |
Douglas Gregor | c788751 | 2008-12-19 19:13:09 +0000 | [diff] [blame] | 52 | |
| 53 | B** bp = ap; // expected-warning{{incompatible pointer types initializing 'B **', expected 'A **'}} |
| 54 | bp = ap; // expected-warning{{incompatible pointer types assigning 'B **', expected 'A **'}} |
Douglas Gregor | 45920e8 | 2008-12-19 17:40:08 +0000 | [diff] [blame] | 55 | } |
| 56 | |
Douglas Gregor | cb7de52 | 2008-11-26 23:31:11 +0000 | [diff] [blame] | 57 | int& cv(A*); |
| 58 | float& cv(const A*); |
| 59 | int& cv2(void*); |
| 60 | float& cv2(const void*); |
| 61 | |
| 62 | void cv_test(A* a, B* b, const A* ac, const B* bc) { |
| 63 | int &i1 = cv(a); |
| 64 | int &i2 = cv(b); |
| 65 | float &f1 = cv(ac); |
| 66 | float &f2 = cv(bc); |
| 67 | int& i3 = cv2(a); |
| 68 | float& f3 = cv2(ac); |
| 69 | } |
Douglas Gregor | 7ca0976 | 2008-11-27 01:19:21 +0000 | [diff] [blame] | 70 | |
| 71 | |
| 72 | int& qualid(id<P0>); |
| 73 | float& qualid(id<P1>); // FIXME: GCC complains that this isn't an overload. Is it? |
| 74 | |
| 75 | void qualid_test(A *a, B *b, C *c) { |
| 76 | int& i1 = qualid(a); |
| 77 | int& i2 = qualid(b); |
| 78 | float& f1 = qualid(c); |
Douglas Gregor | 27b09ac | 2008-12-22 20:51:52 +0000 | [diff] [blame^] | 79 | |
| 80 | id<P0> p1 = 0; |
| 81 | p1 = 0; |
Douglas Gregor | 7ca0976 | 2008-11-27 01:19:21 +0000 | [diff] [blame] | 82 | } |
Douglas Gregor | c788751 | 2008-12-19 19:13:09 +0000 | [diff] [blame] | 83 | |
| 84 | |
| 85 | @class NSException; |
| 86 | typedef struct { |
| 87 | void (*throw_exc)(id); |
| 88 | } |
| 89 | objc_exception_functions_t; |
| 90 | |
| 91 | void (*_NSExceptionRaiser(void))(NSException *) { |
| 92 | objc_exception_functions_t exc_funcs; |
| 93 | return exc_funcs.throw_exc; // expected-warning{{incompatible pointer types returning 'void (*)(NSException *)', expected 'void (*)(id)'}} |
| 94 | } |