summaryrefslogtreecommitdiff
path: root/clang/test/SemaObjC/conditional-expr.m
diff options
context:
space:
mode:
authorCarlo Zancanaro <carlo@pc-4w14-0.cs.usyd.edu.au>2012-10-15 17:10:06 +1100
committerCarlo Zancanaro <carlo@pc-4w14-0.cs.usyd.edu.au>2012-10-15 17:10:06 +1100
commitbe1de4be954c80875ad4108e0a33e8e131b2f2c0 (patch)
tree1fbbecf276bf7c7bdcbb4dd446099d6d90eaa516 /clang/test/SemaObjC/conditional-expr.m
parentc4626a62754862d20b41e8a46a3574264ea80e6d (diff)
parentf1bd2e48c5324d3f7cda4090c87f8a5b6f463ce2 (diff)
Merge branch 'master' of ssh://bitbucket.org/czan/honours
Diffstat (limited to 'clang/test/SemaObjC/conditional-expr.m')
-rw-r--r--clang/test/SemaObjC/conditional-expr.m119
1 files changed, 119 insertions, 0 deletions
diff --git a/clang/test/SemaObjC/conditional-expr.m b/clang/test/SemaObjC/conditional-expr.m
new file mode 100644
index 0000000..e0a3210
--- /dev/null
+++ b/clang/test/SemaObjC/conditional-expr.m
@@ -0,0 +1,119 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -pedantic -Wno-objc-root-class %s
+@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
+
+@interface DTFilterOutputStream2
+- nextOutputStream; // expected-note {{method definition for 'nextOutputStream' not found}}
+@end
+
+@implementation DTFilterOutputStream2 // expected-warning {{incomplete implementation}}
+- (id)initWithNextOutputStream:(id <DTOutputStreams>) outputStream {
+ id <DTOutputStreams> nextOutputStream = [self nextOutputStream];
+ self = nextOutputStream; // expected-warning {{assigning to 'DTFilterOutputStream2 *' from incompatible type 'id<DTOutputStreams>'}}
+ return nextOutputStream ? nextOutputStream : self; // expected-warning {{incompatible operand types ('id<DTOutputStreams>' and 'DTFilterOutputStream2 *')}}
+}
+@end
+
+// No @interface declaration for DTFilterOutputStream3
+@implementation DTFilterOutputStream3 // expected-warning {{cannot find interface declaration for 'DTFilterOutputStream3'}}
+- (id)initWithNextOutputStream:(id <DTOutputStreams>) outputStream {
+ id <DTOutputStreams> nextOutputStream = [self nextOutputStream]; // expected-warning {{method '-nextOutputStream' not found (return type defaults to 'id')}}
+ self = nextOutputStream; // expected-warning {{assigning to 'DTFilterOutputStream3 *' from incompatible type 'id<DTOutputStreams>'}}
+ return nextOutputStream ? nextOutputStream : self; // expected-warning {{incompatible operand types ('id<DTOutputStreams>' and 'DTFilterOutputStream3 *')}}
+}
+@end
+
+//
+
+@protocol P0
+@property int intProp;
+@end
+@protocol P1
+@end
+@protocol P2
+@end
+
+@interface A <P0>
+@end
+
+@interface B : A
+@end
+
+@interface C
+@end
+
+@interface D
+@end
+
+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) {
+ (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'}}
+}
+
+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'}}
+}
+
+id f7(int a, id<P0> x, A* p) {
+ return a ? x : p;
+}
+
+void f8(int a, A<P0> *x, A *y) {
+ [ (a ? x : y ) intProp ];
+}
+
+void f9(int a, A<P0> *x, A<P1> *y) {
+ id l0 = (a ? x : y ); // expected-warning {{incompatible operand types ('A<P0> *' and 'A<P1> *')}}
+ A<P0> *l1 = (a ? x : y ); // expected-warning {{incompatible operand types ('A<P0> *' and 'A<P1> *')}}
+ A<P1> *l2 = (a ? x : y ); // expected-warning {{incompatible operand types ('A<P0> *' and 'A<P1> *')}}
+ [ (a ? x : y ) intProp ]; // expected-warning {{incompatible operand types ('A<P0> *' and 'A<P1> *')}}
+}
+
+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) {
+ A<P1>* l0 = (a ? x : y ); // expected-warning {{incompatible operand types ('A<P0> *' and 'A<P1> *')}}
+}