blob: 71bdb1b2d341b44e2f44130500b646a5199ad6fb [file] [log] [blame]
Patrick Beardacfbe9e2012-04-06 18:12:22 +00001// RUN: %clang_cc1 -fsyntax-only -verify -pedantic -Wno-objc-root-class %s
Steve Naroff524011f2008-05-31 22:33:45 +00002@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 Naroff09efde02008-05-31 23:10:15 +000022
23@interface DTFilterOutputStream2
Ted Kremenek65d63572013-03-27 00:02:21 +000024- nextOutputStream; // expected-note {{method 'nextOutputStream' declared here}}
Steve Naroff09efde02008-05-31 23:10:15 +000025@end
26
Ted Kremenek65d63572013-03-27 00:02:21 +000027@implementation DTFilterOutputStream2 // expected-warning {{method definition for 'nextOutputStream' not found}}
Steve Naroff09efde02008-05-31 23:10:15 +000028- (id)initWithNextOutputStream:(id <DTOutputStreams>) outputStream {
29 id <DTOutputStreams> nextOutputStream = [self nextOutputStream];
Douglas Gregorc68e1402010-04-09 00:35:39 +000030 self = nextOutputStream; // expected-warning {{assigning to 'DTFilterOutputStream2 *' from incompatible type 'id<DTOutputStreams>'}}
Steve Naroff8e6aee52009-07-23 01:01:38 +000031 return nextOutputStream ? nextOutputStream : self; // expected-warning {{incompatible operand types ('id<DTOutputStreams>' and 'DTFilterOutputStream2 *')}}
Steve Naroff09efde02008-05-31 23:10:15 +000032}
33@end
34
35// No @interface declaration for DTFilterOutputStream3
Fariborz Jahanian773df4a2013-05-14 23:24:17 +000036@implementation DTFilterOutputStream3 // expected-warning {{cannot find interface declaration for 'DTFilterOutputStream3'}} \
Fariborz Jahanian478536b2013-05-15 15:27:35 +000037 // expected-note {{receiver is instance of class declared here}}
Steve Naroff09efde02008-05-31 23:10:15 +000038- (id)initWithNextOutputStream:(id <DTOutputStreams>) outputStream {
Steve Naroff3f49fee2009-03-04 15:11:40 +000039 id <DTOutputStreams> nextOutputStream = [self nextOutputStream]; // expected-warning {{method '-nextOutputStream' not found (return type defaults to 'id')}}
Douglas Gregorc68e1402010-04-09 00:35:39 +000040 self = nextOutputStream; // expected-warning {{assigning to 'DTFilterOutputStream3 *' from incompatible type 'id<DTOutputStreams>'}}
Steve Naroff8e6aee52009-07-23 01:01:38 +000041 return nextOutputStream ? nextOutputStream : self; // expected-warning {{incompatible operand types ('id<DTOutputStreams>' and 'DTFilterOutputStream3 *')}}
Steve Naroff09efde02008-05-31 23:10:15 +000042}
43@end
Daniel Dunbar0418a5f2009-07-16 21:55:48 +000044
45//
46
47@protocol P0
48@property int intProp;
49@end
50@protocol P1
51@end
52@protocol P2
53@end
Douglas Gregorc5e07f52015-07-07 03:58:01 +000054@protocol P3 <P1>
55@end
56@protocol P4 <P1>
57@end
Daniel Dunbar0418a5f2009-07-16 21:55:48 +000058
59@interface A <P0>
60@end
61
62@interface B : A
63@end
64
65@interface C
66@end
67
68@interface D
69@end
70
Douglas Gregorc5e07f52015-07-07 03:58:01 +000071@interface E : A
72@end
73
Daniel Dunbar0418a5f2009-07-16 21:55:48 +000074void f0(id<P0> x) {
75 x.intProp = 1;
76}
77
78void f1(int cond, id<P0> x, id<P0> y) {
79 (cond ? x : y).intProp = 1;
80}
81
82void f2(int cond, id<P0> x, A *y) {
83 (cond ? x : y).intProp = 1;
84}
85
86void f3(int cond, id<P0> x, B *y) {
87 (cond ? x : y).intProp = 1;
88}
89
90void f4(int cond, id x, B *y) {
91 (cond ? x : y).intProp = 1; // expected-error {{property 'intProp' not found on object of type 'id'}}
92}
93
94void f5(int cond, id<P0> x, C *y) {
Steve Naroff8e6aee52009-07-23 01:01:38 +000095 (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'}}
Daniel Dunbar0418a5f2009-07-16 21:55:48 +000096}
97
98void 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'}}
100}
Daniel Dunbara3f41f42009-07-16 23:34:22 +0000101
102id f7(int a, id<P0> x, A* p) {
103 return a ? x : p;
104}
105
Fariborz Jahanianac6b4ef2014-07-18 22:59:10 +0000106int f8(int a, A<P0> *x, A *y) {
107 return [ (a ? x : y ) intProp ];
Daniel Dunbara3f41f42009-07-16 23:34:22 +0000108}
109
110void f9(int a, A<P0> *x, A<P1> *y) {
Fariborz Jahanian12f7ef32014-10-13 21:07:45 +0000111 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.
Daniel Dunbara3f41f42009-07-16 23:34:22 +0000115}
116
117void f10(int a, id<P0> x, id y) {
118 [ (a ? x : y ) intProp ];
119}
120
121void f11(int a, id<P0> x, id<P1> y) {
122 [ (a ? x : y ) intProp ]; // expected-warning {{incompatible operand types ('id<P0>' and 'id<P1>')}}
123}
124
125void f12(int a, A<P0> *x, A<P1> *y) {
Fariborz Jahanian12f7ef32014-10-13 21:07:45 +0000126 A<P1>* l0 = (a ? x : y ); // expected-warning {{incompatible pointer types initializing 'A<P1> *' with an expression of type 'A<P0> *'}}
Daniel Dunbara3f41f42009-07-16 23:34:22 +0000127}
Douglas Gregorc5e07f52015-07-07 03:58:01 +0000128
129void f13(int a, B<P3, P0> *x, E<P0, P4> *y) {
130 int *ip = a ? x : y; // expected-warning{{expression of type 'A<P1> *'}}
131}