Keep the source location of the selector in ObjCMessageExpr.
[clang.git] / test / SemaObjC / conditional-expr.m
blob74ab59bdb9ed92f90bdab01d6dcf0e77ec013994
1 // RUN: %clang_cc1 -fsyntax-only -verify -pedantic %s
2 @protocol NSObject
3 @end
5 @protocol DTOutputStreams <NSObject>
6 @end
8 @interface DTFilterOutputStream <DTOutputStreams>
9 - nextOutputStream;
10 @end
12 @implementation DTFilterOutputStream
13 - (id)initWithNextOutputStream:(id <DTOutputStreams>) outputStream {
14   id <DTOutputStreams> nextOutputStream = [self nextOutputStream];
15   self = nextOutputStream;
16   return nextOutputStream ? nextOutputStream : self;
18 - nextOutputStream {
19   return self;
21 @end
23 @interface DTFilterOutputStream2
24 - nextOutputStream; // expected-note {{{{method definition for 'nextOutputStream' not found}}
25 @end
27 @implementation DTFilterOutputStream2 // expected-warning {{incomplete implementation}}
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 *')}}
33 @end
35 // No @interface declaration for DTFilterOutputStream3
36 @implementation DTFilterOutputStream3 // expected-warning {{cannot find interface declaration for 'DTFilterOutputStream3'}}
37 - (id)initWithNextOutputStream:(id <DTOutputStreams>) outputStream {
38   id <DTOutputStreams> nextOutputStream = [self nextOutputStream]; // expected-warning {{method '-nextOutputStream' not found (return type defaults to 'id')}}
39   self = nextOutputStream; // expected-warning {{assigning to 'DTFilterOutputStream3 *' from incompatible type 'id<DTOutputStreams>'}}
40   return nextOutputStream ? nextOutputStream : self; // expected-warning {{incompatible operand types ('id<DTOutputStreams>' and 'DTFilterOutputStream3 *')}}
42 @end
46 @protocol P0
47 @property int intProp;
48 @end
49 @protocol P1
50 @end
51 @protocol P2
52 @end
54 @interface A <P0>
55 @end
57 @interface B : A
58 @end
60 @interface C
61 @end
63 @interface D
64 @end
66 void f0(id<P0> x) {
67   x.intProp = 1;
70 void f1(int cond, id<P0> x, id<P0> y) {
71   (cond ? x : y).intProp = 1;
74 void f2(int cond, id<P0> x, A *y) {
75   (cond ? x : y).intProp = 1;
78 void f3(int cond, id<P0> x, B *y) {
79   (cond ? x : y).intProp = 1;
82 void f4(int cond, id x, B *y) {
83   (cond ? x : y).intProp = 1; // expected-error {{property 'intProp' not found on object of type 'id'}}
86 void f5(int cond, id<P0> x, C *y) {
87   (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'}}
90 void f6(int cond, C *x, D *y) {
91   (cond ? x : y).intProp = 1; // expected-warning {{incompatible operand types}}, expected-error {{property 'intProp' not found on object of type 'id'}}
94 id f7(int a, id<P0> x, A* p) {
95   return a ? x : p;
98 void f8(int a, A<P0> *x, A *y) {
99   [ (a ? x : y ) intProp ];
102 void f9(int a, A<P0> *x, A<P1> *y) {
103   id l0 = (a ? x : y ); // expected-warning {{incompatible operand types ('A<P0> *' and 'A<P1> *')'}}
104   A<P0> *l1 = (a ? x : y ); // expected-warning {{incompatible operand types ('A<P0> *' and 'A<P1> *')}}
105   A<P1> *l2 = (a ? x : y ); // expected-warning {{incompatible operand types ('A<P0> *' and 'A<P1> *')}}
106   [ (a ? x : y ) intProp ]; // expected-warning {{incompatible operand types ('A<P0> *' and 'A<P1> *')}}
109 void f10(int a, id<P0> x, id y) {
110   [ (a ? x : y ) intProp ];
113 void f11(int a, id<P0> x, id<P1> y) {
114   [ (a ? x : y ) intProp ]; // expected-warning {{incompatible operand types ('id<P0>' and 'id<P1>')}}
117 void f12(int a, A<P0> *x, A<P1> *y) {
118   A<P1>* l0 = (a ? x : y ); // expected-warning {{incompatible operand types ('A<P0> *' and 'A<P1> *')}}