2012-04-07 02:12:22 +08:00
|
|
|
// RUN: %clang_cc1 -fsyntax-only -verify -pedantic -Wno-objc-root-class %s
|
2008-06-01 06:33:45 +08:00
|
|
|
@protocol NSObject
|
|
|
|
@end
|
|
|
|
|
|
|
|
@protocol DTOutputStreams <NSObject>
|
|
|
|
@end
|
|
|
|
|
|
|
|
@interface DTFilterOutputStream <DTOutputStreams>
|
|
|
|
- nextOutputStream;
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation DTFilterOutputStream
|
|
|
|
- (id)initWithNextOutputStream:(id <DTOutputStreams>) outputStream {
|
|
|
|
id <DTOutputStreams> nextOutputStream = [self nextOutputStream];
|
|
|
|
self = nextOutputStream;
|
|
|
|
return nextOutputStream ? nextOutputStream : self;
|
|
|
|
}
|
|
|
|
- nextOutputStream {
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
@end
|
2008-06-01 07:10:15 +08:00
|
|
|
|
|
|
|
@interface DTFilterOutputStream2
|
2013-03-27 08:02:21 +08:00
|
|
|
- nextOutputStream; // expected-note {{method 'nextOutputStream' declared here}}
|
2008-06-01 07:10:15 +08:00
|
|
|
@end
|
|
|
|
|
2013-03-27 08:02:21 +08:00
|
|
|
@implementation DTFilterOutputStream2 // expected-warning {{method definition for 'nextOutputStream' not found}}
|
2008-06-01 07:10:15 +08:00
|
|
|
- (id)initWithNextOutputStream:(id <DTOutputStreams>) outputStream {
|
|
|
|
id <DTOutputStreams> nextOutputStream = [self nextOutputStream];
|
2010-04-09 08:35:39 +08:00
|
|
|
self = nextOutputStream; // expected-warning {{assigning to 'DTFilterOutputStream2 *' from incompatible type 'id<DTOutputStreams>'}}
|
2009-07-23 09:01:38 +08:00
|
|
|
return nextOutputStream ? nextOutputStream : self; // expected-warning {{incompatible operand types ('id<DTOutputStreams>' and 'DTFilterOutputStream2 *')}}
|
2008-06-01 07:10:15 +08:00
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
|
|
|
// No @interface declaration for DTFilterOutputStream3
|
2013-05-15 07:24:17 +08:00
|
|
|
@implementation DTFilterOutputStream3 // expected-warning {{cannot find interface declaration for 'DTFilterOutputStream3'}} \
|
2013-05-15 23:27:35 +08:00
|
|
|
// expected-note {{receiver is instance of class declared here}}
|
2008-06-01 07:10:15 +08:00
|
|
|
- (id)initWithNextOutputStream:(id <DTOutputStreams>) outputStream {
|
2009-03-04 23:11:40 +08:00
|
|
|
id <DTOutputStreams> nextOutputStream = [self nextOutputStream]; // expected-warning {{method '-nextOutputStream' not found (return type defaults to 'id')}}
|
2010-04-09 08:35:39 +08:00
|
|
|
self = nextOutputStream; // expected-warning {{assigning to 'DTFilterOutputStream3 *' from incompatible type 'id<DTOutputStreams>'}}
|
2009-07-23 09:01:38 +08:00
|
|
|
return nextOutputStream ? nextOutputStream : self; // expected-warning {{incompatible operand types ('id<DTOutputStreams>' and 'DTFilterOutputStream3 *')}}
|
2008-06-01 07:10:15 +08:00
|
|
|
}
|
|
|
|
@end
|
2009-07-17 05:55:48 +08:00
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
@protocol P0
|
|
|
|
@property int intProp;
|
|
|
|
@end
|
|
|
|
@protocol P1
|
|
|
|
@end
|
|
|
|
@protocol P2
|
|
|
|
@end
|
2015-07-07 11:58:01 +08:00
|
|
|
@protocol P3 <P1>
|
|
|
|
@end
|
|
|
|
@protocol P4 <P1>
|
|
|
|
@end
|
2009-07-17 05:55:48 +08:00
|
|
|
|
|
|
|
@interface A <P0>
|
|
|
|
@end
|
|
|
|
|
|
|
|
@interface B : A
|
|
|
|
@end
|
|
|
|
|
|
|
|
@interface C
|
|
|
|
@end
|
|
|
|
|
|
|
|
@interface D
|
|
|
|
@end
|
|
|
|
|
2015-07-07 11:58:01 +08:00
|
|
|
@interface E : A
|
|
|
|
@end
|
|
|
|
|
2009-07-17 05:55:48 +08:00
|
|
|
void f0(id<P0> x) {
|
|
|
|
x.intProp = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void f1(int cond, id<P0> x, id<P0> y) {
|
|
|
|
(cond ? x : y).intProp = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void f2(int cond, id<P0> x, A *y) {
|
|
|
|
(cond ? x : y).intProp = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void f3(int cond, id<P0> x, B *y) {
|
|
|
|
(cond ? x : y).intProp = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void f4(int cond, id x, B *y) {
|
|
|
|
(cond ? x : y).intProp = 1; // expected-error {{property 'intProp' not found on object of type 'id'}}
|
|
|
|
}
|
|
|
|
|
|
|
|
void f5(int cond, id<P0> x, C *y) {
|
2009-07-23 09:01:38 +08:00
|
|
|
(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'}}
|
2009-07-17 05:55:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void f6(int cond, C *x, D *y) {
|
|
|
|
(cond ? x : y).intProp = 1; // expected-warning {{incompatible operand types}}, expected-error {{property 'intProp' not found on object of type 'id'}}
|
|
|
|
}
|
2009-07-17 07:34:22 +08:00
|
|
|
|
|
|
|
id f7(int a, id<P0> x, A* p) {
|
|
|
|
return a ? x : p;
|
|
|
|
}
|
|
|
|
|
2014-07-19 06:59:10 +08:00
|
|
|
int f8(int a, A<P0> *x, A *y) {
|
|
|
|
return [ (a ? x : y ) intProp ];
|
2009-07-17 07:34:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void f9(int a, A<P0> *x, A<P1> *y) {
|
2014-10-14 05:07:45 +08:00
|
|
|
id l0 = (a ? x : y ); // Ok. y is of A<P1> object type and A is qualified by P0.
|
|
|
|
A<P0> *l1 = (a ? x : y ); // Ok. y is of A<P1> object type and A is qualified by P0.
|
|
|
|
A<P1> *l2 = (a ? x : y ); // expected-warning {{incompatible pointer types initializing 'A<P1> *' with an expression of type 'A<P0> *'}}
|
|
|
|
(void)[ (a ? x : y ) intProp ]; // Ok. Common type is A<P0> * and P0's property intProp is accessed.
|
2009-07-17 07:34:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void f10(int a, id<P0> x, id y) {
|
|
|
|
[ (a ? x : y ) intProp ];
|
|
|
|
}
|
|
|
|
|
|
|
|
void f11(int a, id<P0> x, id<P1> y) {
|
|
|
|
[ (a ? x : y ) intProp ]; // expected-warning {{incompatible operand types ('id<P0>' and 'id<P1>')}}
|
|
|
|
}
|
|
|
|
|
|
|
|
void f12(int a, A<P0> *x, A<P1> *y) {
|
2014-10-14 05:07:45 +08:00
|
|
|
A<P1>* l0 = (a ? x : y ); // expected-warning {{incompatible pointer types initializing 'A<P1> *' with an expression of type 'A<P0> *'}}
|
2009-07-17 07:34:22 +08:00
|
|
|
}
|
2015-07-07 11:58:01 +08:00
|
|
|
|
|
|
|
void f13(int a, B<P3, P0> *x, E<P0, P4> *y) {
|
|
|
|
int *ip = a ? x : y; // expected-warning{{expression of type 'A<P1> *'}}
|
|
|
|
}
|