Daniel Dunbar | d7d5f02 | 2009-03-24 02:24:46 +0000 | [diff] [blame] | 1 | // RUN: clang-cc -fsyntax-only -verify -pedantic %s |
Steve Naroff | aa73eec | 2008-05-31 22:33:45 +0000 | [diff] [blame] | 2 | @protocol NSObject |
| 3 | @end |
| 4 | |
| 5 | @protocol DTOutputStreams <NSObject> |
| 6 | @end |
| 7 | |
| 8 | @interface DTFilterOutputStream <DTOutputStreams> |
| 9 | - nextOutputStream; |
| 10 | @end |
| 11 | |
| 12 | @implementation DTFilterOutputStream |
| 13 | - (id)initWithNextOutputStream:(id <DTOutputStreams>) outputStream { |
| 14 | id <DTOutputStreams> nextOutputStream = [self nextOutputStream]; |
| 15 | self = nextOutputStream; |
| 16 | return nextOutputStream ? nextOutputStream : self; |
| 17 | } |
| 18 | - nextOutputStream { |
| 19 | return self; |
| 20 | } |
| 21 | @end |
Steve Naroff | 19b87d2 | 2008-05-31 23:10:15 +0000 | [diff] [blame] | 22 | |
| 23 | @interface DTFilterOutputStream2 |
| 24 | - nextOutputStream; |
| 25 | @end |
| 26 | |
| 27 | @implementation DTFilterOutputStream2 // expected-warning {{incomplete implementation}} expected-warning {{method definition for 'nextOutputStream' not found}} |
| 28 | - (id)initWithNextOutputStream:(id <DTOutputStreams>) outputStream { |
| 29 | id <DTOutputStreams> nextOutputStream = [self nextOutputStream]; |
| 30 | // GCC warns about both of these. |
Steve Naroff | 3957907 | 2008-10-14 22:18:38 +0000 | [diff] [blame] | 31 | self = nextOutputStream; // expected-warning {{incompatible type assigning 'id<DTOutputStreams>', expected 'DTFilterOutputStream2 *'}} |
Daniel Dunbar | 40727a4 | 2008-09-03 17:53:25 +0000 | [diff] [blame] | 32 | return nextOutputStream ? nextOutputStream : self; |
Steve Naroff | 19b87d2 | 2008-05-31 23:10:15 +0000 | [diff] [blame] | 33 | } |
| 34 | @end |
| 35 | |
| 36 | // No @interface declaration for DTFilterOutputStream3 |
| 37 | @implementation DTFilterOutputStream3 // expected-warning {{cannot find interface declaration for 'DTFilterOutputStream3'}} |
| 38 | - (id)initWithNextOutputStream:(id <DTOutputStreams>) outputStream { |
Steve Naroff | 6b9dfd4 | 2009-03-04 15:11:40 +0000 | [diff] [blame] | 39 | id <DTOutputStreams> nextOutputStream = [self nextOutputStream]; // expected-warning {{method '-nextOutputStream' not found (return type defaults to 'id')}} |
Steve Naroff | 19b87d2 | 2008-05-31 23:10:15 +0000 | [diff] [blame] | 40 | // GCC warns about both of these as well (no errors). |
Steve Naroff | 3957907 | 2008-10-14 22:18:38 +0000 | [diff] [blame] | 41 | self = nextOutputStream; // expected-warning {{incompatible type assigning 'id<DTOutputStreams>', expected 'DTFilterOutputStream3 *'}} |
Daniel Dunbar | 40727a4 | 2008-09-03 17:53:25 +0000 | [diff] [blame] | 42 | return nextOutputStream ? nextOutputStream : self; |
Steve Naroff | 19b87d2 | 2008-05-31 23:10:15 +0000 | [diff] [blame] | 43 | } |
| 44 | @end |
Daniel Dunbar | 1cdad9e | 2009-07-16 21:55:48 +0000 | [diff] [blame^] | 45 | |
| 46 | // |
| 47 | |
| 48 | @protocol P0 |
| 49 | @property int intProp; |
| 50 | @end |
| 51 | @protocol P1 |
| 52 | @end |
| 53 | @protocol P2 |
| 54 | @end |
| 55 | |
| 56 | @interface A <P0> |
| 57 | @end |
| 58 | |
| 59 | @interface B : A |
| 60 | @end |
| 61 | |
| 62 | @interface C |
| 63 | @end |
| 64 | |
| 65 | @interface D |
| 66 | @end |
| 67 | |
| 68 | void f0(id<P0> x) { |
| 69 | x.intProp = 1; |
| 70 | } |
| 71 | |
| 72 | void f1(int cond, id<P0> x, id<P0> y) { |
| 73 | (cond ? x : y).intProp = 1; |
| 74 | } |
| 75 | |
| 76 | void f2(int cond, id<P0> x, A *y) { |
| 77 | (cond ? x : y).intProp = 1; |
| 78 | } |
| 79 | |
| 80 | void f3(int cond, id<P0> x, B *y) { |
| 81 | (cond ? x : y).intProp = 1; |
| 82 | } |
| 83 | |
| 84 | void f4(int cond, id x, B *y) { |
| 85 | (cond ? x : y).intProp = 1; // expected-error {{property 'intProp' not found on object of type 'id'}} |
| 86 | } |
| 87 | |
| 88 | void f5(int cond, id<P0> x, C *y) { |
| 89 | (cond ? x : y).intProp = 1; // expected-error {{property 'intProp' not found on object of type 'C *'}} |
| 90 | } |
| 91 | |
| 92 | void f6(int cond, C *x, D *y) { |
| 93 | (cond ? x : y).intProp = 1; // expected-warning {{incompatible operand types}}, expected-error {{property 'intProp' not found on object of type 'id'}} |
| 94 | } |