2 /* Check Class <protocol> types */
3 /* Author: David Ayers <d.ayers@inode.at> */
4 /* { dg-do compile } */
7 #include <objc/objc-api.h>
19 @interface MyClass1 <MyProto1>
24 @implementation MyClass1
26 -(void)doItInstance1{}
29 @interface MyClass2 : MyClass1 <MyProto2>
31 @implementation MyClass2
33 -(void)doItInstance2{}
41 @interface MyClass4 : MyClass3 <MyProto1>
44 /*----------------------------------------*/
47 Class <MyProto1> clsP1 = 0;
48 Class <MyProto2> clsP2 = 0;
59 [clsP1 doItInstance1]; /* { dg-warning "instead of" } */
60 [clsP1 doItClass2]; /* { dg-warning "not found in protocol" } */
61 [clsP1 doItInstance2]; /* { dg-warning "not found in protocol" } */
63 [clsP2 doItClass1]; /* { dg-warning "not found in protocol" } */
64 [clsP2 doItInstance1]; /* { dg-warning "not found in protocol" } */
66 [clsP2 doItInstance2]; /* { dg-warning "instead of" } */
68 [MyClass1 doItClass1];
69 [MyClass1 doItInstance1];
70 [MyClass1 doItClass2]; /* { dg-warning "may not respond to" } */
71 [MyClass1 doItInstance2]; /* { dg-warning "may not respond to" } */
73 [MyClass2 doItClass1];
74 [MyClass2 doItInstance1];
75 [MyClass2 doItClass2];
76 [MyClass2 doItInstance2]; /* { dg-warning "may not respond to" } */
78 [MyClass3 doItClass1]; /* { dg-warning "may not respond to" } */
79 [MyClass3 doItInstance1]; /* { dg-warning "may not respond to" } */
81 [MyClass4 doItClass1];
82 [MyClass4 doItInstance1]; /* { dg-warning "may not respond to" } */
85 /*----------------------------------------*/
86 /* Protocols declared by categories */
97 @interface MyClass1 (Category1) <MyProto3>
99 @interface MyClass2 (Category2) <MyProto4>
110 [MyClass1 doItClass3];
111 [MyClass1 doItInstance3];
112 [MyClass1 doItClass4]; /* { dg-warning "may not respond" } */
113 [MyClass1 doItInstance4]; /* { dg-warning "may not respond" } */
115 [MyClass2 doItClass3];
116 [MyClass2 doItInstance3];
117 [MyClass2 doItClass4];
118 [MyClass2 doItInstance4]; /* { dg-warning "may not respond" } */
122 /*----------------------------------------*/
123 /* Inherited protocols declared by categories */
125 @protocol MyProto5 <MyProto1>
127 -(void)doItInstance5;
130 @protocol MyProto6 <MyProto2>
132 -(void)doItInstance6;
135 @interface MyClass1 (Category3) <MyProto5>
137 @interface MyClass2 (Category4) <MyProto6>
140 Class <MyProto5> clsP5 = 0;
141 Class <MyProto6> clsP6 = 0;
144 testCategoryInherited(void)
152 [clsP5 doItInstance1]; /* { dg-warning "instead of" } */
153 [clsP5 doItClass2]; /* { dg-warning "not found in protocol" } */
154 [clsP5 doItInstance2]; /* { dg-warning "not found in protocol" } */
156 [clsP6 doItClass1]; /* { dg-warning "not found in protocol" } */
157 [clsP6 doItInstance1]; /* { dg-warning "not found in protocol" } */
159 [clsP6 doItInstance2]; /* { dg-warning "instead of" } */
162 [MyClass1 doItClass5];
163 [MyClass1 doItInstance5];
164 [MyClass1 doItClass6]; /* { dg-warning "may not respond" } */
165 [MyClass1 doItInstance6]; /* { dg-warning "may not respond" } */
167 [MyClass2 doItClass5];
168 [MyClass2 doItInstance5];
169 [MyClass2 doItClass6];
170 [MyClass2 doItInstance6]; /* { dg-warning "may not respond" } */
174 /*----------------------------------------*/
175 /* Forward declared root protocols */
179 @interface MyClass1 (Forward) <FwProto>
182 Class <FwProto> clsP7 = 0;
185 testForwardeDeclared1(void)
187 [cls doItClass7]; /* { dg-warning "no .\\+doItClass7. method found" } */
188 [cls doItInstance7]; /* { dg-warning "no .\\+doItInstance7. method found" } */
190 [clsP7 doItClass7]; /* { dg-warning "not found in protocol" } */
191 /* { dg-warning "no .\\+doItClass7. method found" "" { target *-*-* } 190 } */
192 [clsP7 doItInstance7]; /* { dg-warning "not found in protocol" } */
193 /* { dg-warning "no .\\+doItInstance7. method found" "" { target *-*-* } 192 } */
195 [MyClass1 doItClass7]; /* { dg-warning "may not respond" } */
196 [MyClass1 doItInstance7]; /* { dg-warning "may not respond" } */
198 [MyClass2 doItClass7]; /* { dg-warning "may not respond" } */
199 [MyClass2 doItInstance7]; /* { dg-warning "may not respond" } */
205 -(void)doItInstance7;
209 testForwardeDeclared2(void)
215 [clsP7 doItInstance7]; /* { dg-warning "instead of" } */
217 [MyClass1 doItClass7];
218 [MyClass1 doItInstance7];
220 [MyClass2 doItClass7];
221 [MyClass2 doItInstance7];
224 /*----------------------------------------*/
225 /* Inherited non root protocols */
229 -(void)doItInstance8;
232 @protocol MyProto9 <MyProto8>
234 -(void)doItInstance9;
237 @interface MyClass1 (InheritedNonRoot) <MyProto9>
240 Class <MyProto8> clsP8 = 0;
241 Class <MyProto9> clsP9 = 0;
244 testInheritedNonRoot(void)
252 [clsP8 doItInstance8]; /* { dg-warning "instead of" } */
253 [clsP8 doItClass9]; /* { dg-warning "not found in protocol" } */
254 [clsP8 doItInstance9]; /* { dg-warning "not found in protocol" } */
257 [clsP9 doItInstance8]; /* { dg-warning "instead of" } */
259 [clsP9 doItInstance9]; /* { dg-warning "instead of" } */
261 [MyClass1 doItClass8];
262 [MyClass1 doItInstance8];
263 [MyClass1 doItClass9];
264 [MyClass1 doItInstance9];
266 [MyClass2 doItClass8];
267 [MyClass2 doItInstance8];
268 [MyClass2 doItClass9];
269 [MyClass2 doItInstance9];
273 /*----------------------------------------*/
274 /* Prototype mismatch */
276 @protocol MyOtherProto1
280 @interface MyOtherClass1 <MyOtherProto1>
283 Class <MyOtherProto1> oclsP1;
286 testPrototypeMismatch(void)
288 id tmp1 = [oclsP1 doItClass1];
289 id tmp2 = [oclsP1 doItInstance1]; /* { dg-warning "instead of" } */
292 [clsP1 doItInstance1]; /* { dg-warning "instead of" } */
296 id <MyProto1> objP1 = nil;
297 id <MyProto2> objP2 = nil;
298 id <MyProto5> objP5 = nil;
307 { /* id <protocol>, id <protocol> */
308 objP1 == objP2; /* { dg-warning "lacks a cast" } */
309 objP2 == objP1; /* { dg-warning "lacks a cast" } */
314 { /* id <protocol>, SomeClass * */
318 mc1 == objP2; /* { dg-warning "lacks a cast" } */
319 objP2 == mc1; /* { dg-warning "lacks a cast" } */
321 { /* id <protocol>, id */
325 { /* id <protocol>, Class */
326 cls == objP1; /* { dg-warning "lacks a cast" } */
327 objP1 == cls; /* { dg-warning "lacks a cast" } */
329 { /* id <protocol>, non-ObjC */
330 num == objP1; /* { dg-warning "between pointer" } */
331 objP1 == num; /* { dg-warning "between pointer" } */
336 { /* Class <protocol>, Class <protocol> */
337 clsP1 == clsP2; /* { dg-warning "lacks a cast" } */
338 clsP2 == clsP1; /* { dg-warning "lacks a cast" } */
343 { /* Class <protocol>, SomeClass * */
344 mc1 == clsP1; /* { dg-warning "lacks a cast" } */
345 clsP1 == mc1; /* { dg-warning "lacks a cast" } */
347 { /* Class <protocol>, id */
351 { /* Class <protocol>, Class */
355 { /* Class <protocol>, non-ObjC */
356 num == clsP1; /* { dg-warning "between pointer" } */
357 clsP1 == num; /* { dg-warning "between pointer" } */
362 { /* Class <protocol>, id <protocol> */
363 clsP1 == objP1; /* { dg-warning "lacks a cast" } */
364 objP1 == clsP1; /* { dg-warning "lacks a cast" } */
367 { /* id <protocol>, id <protocol> */
368 objP1 = objP2; /* { dg-warning "does not conform" } */
369 objP2 = objP1; /* { dg-warning "does not conform" } */
372 objP5 = objP1; /* { dg-warning "does not conform" } */
374 { /* id <protocol>, SomeClass * */
378 mc1 = objP2; /* { dg-warning "does not conform" } */
379 objP2 = mc1; /* { dg-warning "does not implement" } */
381 { /* id <protocol>, id */
385 { /* id <protocol>, Class */
386 cls = objP1; /* { dg-warning "distinct Objective\\-C type" } */
387 objP1 = cls; /* { dg-warning "distinct Objective\\-C type" } */
389 { /* id <protocol>, non-ObjC */
390 num = objP1; /* { dg-error "invalid conversion" } */
391 objP1 = num; /* { dg-error "invalid conversion" } */
394 objP1 = ptr; /* { dg-error "invalid conversion" } */
396 { /* Class <protocol>, Class <protocol> */
397 clsP1 = clsP2; /* { dg-warning "does not conform" } */
398 clsP2 = clsP1; /* { dg-warning "does not conform" } */
401 clsP5 = clsP1; /* { dg-warning "does not conform" } */
403 { /* Class <protocol>, SomeClass * */
404 /* These combinations should always elicit a warning. */
405 mc1 = clsP1; /* { dg-warning "distinct Objective\\-C type" } */
406 clsP1 = mc1; /* { dg-warning "distinct Objective\\-C type" } */
408 mc1 = clsP2; /* { dg-warning "distinct Objective\\-C type" } */
409 clsP2 = mc1; /* { dg-warning "distinct Objective\\-C type" } */
411 { /* Class <protocol>, id */
415 { /* Class <protocol>, Class */
419 { /* Class <protocol>, non-ObjC */
420 num = clsP1; /* { dg-error "invalid conversion" } */
421 clsP1 = num; /* { dg-error "invalid conversion" } */
424 clsP1 = ptr; /* { dg-error "invalid conversion" } */
426 { /* Class <protocol>, id <protocol> */
427 clsP1 = objP1; /* { dg-warning "distinct Objective\\-C type" } */
428 objP1 = clsP1; /* { dg-warning "distinct Objective\\-C type" } */
436 testCategoryInherited();
440 /* { dg-warning "Messages without a matching method signature" "" { target *-*-* } 0 } */
441 /* { dg-warning "will be assumed to return .id. and accept" "" { target *-*-* } 0 } */
442 /* { dg-warning ".\.\.\.. as arguments" "" { target *-*-* } 0 } */