1 // RUN: %clang_cc1 -fsyntax-only -verify -pedantic -Wno-objc-root-class %s
5 @protocol DTOutputStreams <NSObject>
8 @interface DTFilterOutputStream <DTOutputStreams>
12 @implementation DTFilterOutputStream
13 - (id)initWithNextOutputStream:(id <DTOutputStreams>) outputStream {
14 id <DTOutputStreams> nextOutputStream = [self nextOutputStream];
15 self = nextOutputStream;
16 return nextOutputStream ? nextOutputStream : self;
23 @interface DTFilterOutputStream2
24 - nextOutputStream; // expected-note {{method 'nextOutputStream' declared here}}
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 *')}}
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 *')}}
48 @property int intProp;
78 void f1(int cond, id<P0> x, id<P0> y) {
79 (cond ? x : y).intProp = 1;
82 void f2(int cond, id<P0> x, A *y) {
83 (cond ? x : y).intProp = 1;
86 void f3(int cond, id<P0> x, B *y) {
87 (cond ? x : y).intProp = 1;
90 void f4(int cond, id x, B *y) {
91 (cond ? x : y).intProp = 1; // expected-error {{property 'intProp' not found on object of type 'id'}}
94 void f5(int cond, id<P0> x, C *y) {
95 (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'}}
98 void f6(int cond, C *x, D *y) {
99 (cond ? x : y).intProp = 1; // expected-warning {{incompatible operand types}}, expected-error {{property 'intProp' not found on object of type 'id'}}
102 id f7(int a, id<P0> x, A* p) {
106 int f8(int a, A<P0> *x, A *y) {
107 return [ (a ? x : y ) intProp ];
110 void f9(int a, A<P0> *x, A<P1> *y) {
111 id l0 = (a ? x : y ); // Ok. y is of A<P1> object type and A is qualified by P0.
112 A<P0> *l1 = (a ? x : y ); // Ok. y is of A<P1> object type and A is qualified by P0.
113 A<P1> *l2 = (a ? x : y ); // expected-warning {{incompatible pointer types initializing 'A<P1> *' with an expression of type 'A<P0> *'}}
114 (void)[ (a ? x : y ) intProp ]; // Ok. Common type is A<P0> * and P0's property intProp is accessed.
117 void f10(int a, id<P0> x, id y) {
118 [ (a ? x : y ) intProp ];
121 void f11(int a, id<P0> x, id<P1> y) {
122 [ (a ? x : y ) intProp ]; // expected-warning {{incompatible operand types ('id<P0>' and 'id<P1>')}}
125 void f12(int a, A<P0> *x, A<P1> *y) {
126 A<P1>* l0 = (a ? x : y ); // expected-warning {{incompatible pointer types initializing 'A<P1> *' with an expression of type 'A<P0> *'}}
129 void f13(int a, B<P3, P0> *x, E<P0, P4> *y) {
130 int *ip = a ? x : y; // expected-warning{{expression of type 'A<P1> *'}}