1// RUN: %clang_cc1 -fsyntax-only -verify -pedantic -Wno-objc-root-class %s 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 22 23@interface DTFilterOutputStream2 24- nextOutputStream; // expected-note {{method 'nextOutputStream' declared here}} 25@end 26 27@implementation DTFilterOutputStream2 // expected-warning {{method definition for 'nextOutputStream' not found}} 28- (id)initWithNextOutputStream:(id <DTOutputStreams>) outputStream { 29 id <DTOutputStreams> nextOutputStream = [self nextOutputStream]; 30 self = nextOutputStream; // expected-warning {{assigning to 'DTFilterOutputStream2 *' from incompatible type 'id<DTOutputStreams>'}} 31 return nextOutputStream ? nextOutputStream : self; // expected-warning {{incompatible operand types ('id<DTOutputStreams>' and 'DTFilterOutputStream2 *')}} 32} 33@end 34 35// No @interface declaration for DTFilterOutputStream3 36@implementation DTFilterOutputStream3 // expected-warning {{cannot find interface declaration for 'DTFilterOutputStream3'}} \ 37 // expected-note {{receiver is instance of class declared here}} 38- (id)initWithNextOutputStream:(id <DTOutputStreams>) outputStream { 39 id <DTOutputStreams> nextOutputStream = [self nextOutputStream]; // expected-warning {{method '-nextOutputStream' not found (return type defaults to 'id')}} 40 self = nextOutputStream; // expected-warning {{assigning to 'DTFilterOutputStream3 *' from incompatible type 'id<DTOutputStreams>'}} 41 return nextOutputStream ? nextOutputStream : self; // expected-warning {{incompatible operand types ('id<DTOutputStreams>' and 'DTFilterOutputStream3 *')}} 42} 43@end 44 45// 46 47@protocol P0 48@property int intProp; 49@end 50@protocol P1 51@end 52@protocol P2 53@end 54 55@interface A <P0> 56@end 57 58@interface B : A 59@end 60 61@interface C 62@end 63 64@interface D 65@end 66 67void f0(id<P0> x) { 68 x.intProp = 1; 69} 70 71void f1(int cond, id<P0> x, id<P0> y) { 72 (cond ? x : y).intProp = 1; 73} 74 75void f2(int cond, id<P0> x, A *y) { 76 (cond ? x : y).intProp = 1; 77} 78 79void f3(int cond, id<P0> x, B *y) { 80 (cond ? x : y).intProp = 1; 81} 82 83void f4(int cond, id x, B *y) { 84 (cond ? x : y).intProp = 1; // expected-error {{property 'intProp' not found on object of type 'id'}} 85} 86 87void f5(int cond, id<P0> x, C *y) { 88 (cond ? x : y).intProp = 1; // expected-warning {{incompatible operand types ('id<P0>' and 'C *')}} expected-error {{property 'intProp' not found on object of type 'id'}} 89} 90 91void f6(int cond, C *x, D *y) { 92 (cond ? x : y).intProp = 1; // expected-warning {{incompatible operand types}}, expected-error {{property 'intProp' not found on object of type 'id'}} 93} 94 95id f7(int a, id<P0> x, A* p) { 96 return a ? x : p; 97} 98 99void f8(int a, A<P0> *x, A *y) { 100 [ (a ? x : y ) intProp ]; 101} 102 103void f9(int a, A<P0> *x, A<P1> *y) { 104 id l0 = (a ? x : y ); // expected-warning {{incompatible operand types ('A<P0> *' and 'A<P1> *')}} 105 A<P0> *l1 = (a ? x : y ); // expected-warning {{incompatible operand types ('A<P0> *' and 'A<P1> *')}} 106 A<P1> *l2 = (a ? x : y ); // expected-warning {{incompatible operand types ('A<P0> *' and 'A<P1> *')}} 107 [ (a ? x : y ) intProp ]; // expected-warning {{incompatible operand types ('A<P0> *' and 'A<P1> *')}} 108} 109 110void f10(int a, id<P0> x, id y) { 111 [ (a ? x : y ) intProp ]; 112} 113 114void f11(int a, id<P0> x, id<P1> y) { 115 [ (a ? x : y ) intProp ]; // expected-warning {{incompatible operand types ('id<P0>' and 'id<P1>')}} 116} 117 118void f12(int a, A<P0> *x, A<P1> *y) { 119 A<P1>* l0 = (a ? x : y ); // expected-warning {{incompatible operand types ('A<P0> *' and 'A<P1> *')}} 120} 121