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