1 /* Check Class <protocol> types */
2 /* Author: David Ayers <d.ayers@inode.at> */
3 /* { dg-do compile } */
6 #include <objc/objc-api.h>
18 @interface MyClass1 <MyProto1>
23 @implementation MyClass1
25 -(void)doItInstance1{}
28 @interface MyClass2 : MyClass1 <MyProto2>
30 @implementation MyClass2
32 -(void)doItInstance2{}
40 @interface MyClass4 : MyClass3 <MyProto1>
43 /*----------------------------------------*/
46 Class <MyProto1> clsP1 = 0;
47 Class <MyProto2> clsP2 = 0;
58 [clsP1 doItInstance1]; /* { dg-warning "instead of" } */
59 [clsP1 doItClass2]; /* { dg-warning "not found in protocol" } */
60 [clsP1 doItInstance2]; /* { dg-warning "not found in protocol" } */
62 [clsP2 doItClass1]; /* { dg-warning "not found in protocol" } */
63 [clsP2 doItInstance1]; /* { dg-warning "not found in protocol" } */
65 [clsP2 doItInstance2]; /* { dg-warning "instead of" } */
67 [MyClass1 doItClass1];
68 [MyClass1 doItInstance1];
69 [MyClass1 doItClass2]; /* { dg-warning "may not respond to" } */
70 [MyClass1 doItInstance2]; /* { dg-warning "may not respond to" } */
72 [MyClass2 doItClass1];
73 [MyClass2 doItInstance1];
74 [MyClass2 doItClass2];
75 [MyClass2 doItInstance2]; /* { dg-warning "may not respond to" } */
77 [MyClass3 doItClass1]; /* { dg-warning "may not respond to" } */
78 [MyClass3 doItInstance1]; /* { dg-warning "may not respond to" } */
80 [MyClass4 doItClass1];
81 [MyClass4 doItInstance1]; /* { dg-warning "may not respond to" } */
84 /*----------------------------------------*/
85 /* Protocols declared by categories */
96 @interface MyClass1 (Category1) <MyProto3>
98 @interface MyClass2 (Category2) <MyProto4>
109 [MyClass1 doItClass3];
110 [MyClass1 doItInstance3];
111 [MyClass1 doItClass4]; /* { dg-warning "may not respond" } */
112 [MyClass1 doItInstance4]; /* { dg-warning "may not respond" } */
114 [MyClass2 doItClass3];
115 [MyClass2 doItInstance3];
116 [MyClass2 doItClass4];
117 [MyClass2 doItInstance4]; /* { dg-warning "may not respond" } */
121 /*----------------------------------------*/
122 /* Inherited protocols declared by categories */
124 @protocol MyProto5 <MyProto1>
126 -(void)doItInstance5;
129 @protocol MyProto6 <MyProto2>
131 -(void)doItInstance6;
134 @interface MyClass1 (Category3) <MyProto5>
136 @interface MyClass2 (Category4) <MyProto6>
139 Class <MyProto5> clsP5 = 0;
140 Class <MyProto6> clsP6 = 0;
143 testCategoryInherited(void)
151 [clsP5 doItInstance1]; /* { dg-warning "instead of" } */
152 [clsP5 doItClass2]; /* { dg-warning "not found in protocol" } */
153 [clsP5 doItInstance2]; /* { dg-warning "not found in protocol" } */
155 [clsP6 doItClass1]; /* { dg-warning "not found in protocol" } */
156 [clsP6 doItInstance1]; /* { dg-warning "not found in protocol" } */
158 [clsP6 doItInstance2]; /* { dg-warning "instead of" } */
161 [MyClass1 doItClass5];
162 [MyClass1 doItInstance5];
163 [MyClass1 doItClass6]; /* { dg-warning "may not respond" } */
164 [MyClass1 doItInstance6]; /* { dg-warning "may not respond" } */
166 [MyClass2 doItClass5];
167 [MyClass2 doItInstance5];
168 [MyClass2 doItClass6];
169 [MyClass2 doItInstance6]; /* { dg-warning "may not respond" } */
173 /*----------------------------------------*/
174 /* Forward declared root protocols */
178 @interface MyClass1 (Forward) <FwProto>
181 Class <FwProto> clsP7 = 0;
184 testForwardeDeclared1(void)
186 [cls doItClass7]; /* { dg-warning "no .\\+doItClass7. method found" } */
187 [cls doItInstance7]; /* { dg-warning "no .\\+doItInstance7. method found" } */
189 [clsP7 doItClass7]; /* { dg-warning "not found in protocol" } */
190 /* { dg-warning "no .\\+doItClass7. method found" "" { target *-*-* } 189 } */
191 [clsP7 doItInstance7]; /* { dg-warning "not found in protocol" } */
192 /* { dg-warning "no .\\+doItInstance7. method found" "" { target *-*-* } 191 } */
194 [MyClass1 doItClass7]; /* { dg-warning "may not respond" } */
195 [MyClass1 doItInstance7]; /* { dg-warning "may not respond" } */
197 [MyClass2 doItClass7]; /* { dg-warning "may not respond" } */
198 [MyClass2 doItInstance7]; /* { dg-warning "may not respond" } */
204 -(void)doItInstance7;
208 testForwardeDeclared2(void)
214 [clsP7 doItInstance7]; /* { dg-warning "instead of" } */
216 [MyClass1 doItClass7];
217 [MyClass1 doItInstance7];
219 [MyClass2 doItClass7];
220 [MyClass2 doItInstance7];
223 /*----------------------------------------*/
224 /* Inherited non root protocols */
228 -(void)doItInstance8;
231 @protocol MyProto9 <MyProto8>
233 -(void)doItInstance9;
236 @interface MyClass1 (InheritedNonRoot) <MyProto9>
239 Class <MyProto8> clsP8 = 0;
240 Class <MyProto9> clsP9 = 0;
243 testInheritedNonRoot(void)
251 [clsP8 doItInstance8]; /* { dg-warning "instead of" } */
252 [clsP8 doItClass9]; /* { dg-warning "not found in protocol" } */
253 [clsP8 doItInstance9]; /* { dg-warning "not found in protocol" } */
256 [clsP9 doItInstance8]; /* { dg-warning "instead of" } */
258 [clsP9 doItInstance9]; /* { dg-warning "instead of" } */
260 [MyClass1 doItClass8];
261 [MyClass1 doItInstance8];
262 [MyClass1 doItClass9];
263 [MyClass1 doItInstance9];
265 [MyClass2 doItClass8];
266 [MyClass2 doItInstance8];
267 [MyClass2 doItClass9];
268 [MyClass2 doItInstance9];
272 /*----------------------------------------*/
273 /* Prototype mismatch */
275 @protocol MyOtherProto1
279 @interface MyOtherClass1 <MyOtherProto1>
282 Class <MyOtherProto1> oclsP1;
285 testPrototypeMismatch(void)
287 id tmp1 = [oclsP1 doItClass1];
288 id tmp2 = [oclsP1 doItInstance1]; /* { dg-warning "instead of" } */
291 [clsP1 doItInstance1]; /* { dg-warning "instead of" } */
295 id <MyProto1> objP1 = nil;
296 id <MyProto2> objP2 = nil;
297 id <MyProto5> objP5 = nil;
306 { /* id <protocol>, id <protocol> */
307 objP1 == objP2; /* { dg-warning "lacks a cast" } */
308 objP2 == objP1; /* { dg-warning "lacks a cast" } */
313 { /* id <protocol>, SomeClass * */
317 mc1 == objP2; /* { dg-warning "lacks a cast" } */
318 objP2 == mc1; /* { dg-warning "lacks a cast" } */
320 { /* id <protocol>, id */
324 { /* id <protocol>, Class */
325 cls == objP1; /* { dg-warning "lacks a cast" } */
326 objP1 == cls; /* { dg-warning "lacks a cast" } */
328 { /* id <protocol>, non-ObjC */
329 num == objP1; /* { dg-warning "between pointer" } */
330 objP1 == num; /* { dg-warning "between pointer" } */
335 { /* Class <protocol>, Class <protocol> */
336 clsP1 == clsP2; /* { dg-warning "lacks a cast" } */
337 clsP2 == clsP1; /* { dg-warning "lacks a cast" } */
342 { /* Class <protocol>, SomeClass * */
343 mc1 == clsP1; /* { dg-warning "lacks a cast" } */
344 clsP1 == mc1; /* { dg-warning "lacks a cast" } */
346 { /* Class <protocol>, id */
350 { /* Class <protocol>, Class */
354 { /* Class <protocol>, non-ObjC */
355 num == clsP1; /* { dg-warning "between pointer" } */
356 clsP1 == num; /* { dg-warning "between pointer" } */
361 { /* Class <protocol>, id <protocol> */
362 clsP1 == objP1; /* { dg-warning "lacks a cast" } */
363 objP1 == clsP1; /* { dg-warning "lacks a cast" } */
366 { /* id <protocol>, id <protocol> */
367 objP1 = objP2; /* { dg-warning "does not conform" } */
368 objP2 = objP1; /* { dg-warning "does not conform" } */
371 objP5 = objP1; /* { dg-warning "does not conform" } */
373 { /* id <protocol>, SomeClass * */
377 mc1 = objP2; /* { dg-warning "does not conform" } */
378 objP2 = mc1; /* { dg-warning "does not implement" } */
380 { /* id <protocol>, id */
384 { /* id <protocol>, Class */
385 cls = objP1; /* { dg-warning "distinct Objective\\-C type" } */
386 objP1 = cls; /* { dg-warning "distinct Objective\\-C type" } */
388 { /* id <protocol>, non-ObjC */
389 num = objP1; /* { dg-warning "makes integer" } */
390 objP1 = num; /* { dg-warning "makes pointer" } */
395 { /* Class <protocol>, Class <protocol> */
396 clsP1 = clsP2; /* { dg-warning "does not conform" } */
397 clsP2 = clsP1; /* { dg-warning "does not conform" } */
400 clsP5 = clsP1; /* { dg-warning "does not conform" } */
402 { /* Class <protocol>, SomeClass * */
403 /* These combinations should always elicit a warning. */
404 mc1 = clsP1; /* { dg-warning "distinct Objective\\-C type" } */
405 clsP1 = mc1; /* { dg-warning "distinct Objective\\-C type" } */
407 mc1 = clsP2; /* { dg-warning "distinct Objective\\-C type" } */
408 clsP2 = mc1; /* { dg-warning "distinct Objective\\-C type" } */
410 { /* Class <protocol>, id */
414 { /* Class <protocol>, Class */
418 { /* Class <protocol>, non-ObjC */
419 num = clsP1; /* { dg-warning "makes integer" } */
420 clsP1 = num; /* { dg-warning "makes pointer" } */
425 { /* Class <protocol>, id <protocol> */
426 clsP1 = objP1; /* { dg-warning "distinct Objective\\-C type" } */
427 objP1 = clsP1; /* { dg-warning "distinct Objective\\-C type" } */
435 testCategoryInherited();
439 /* { dg-warning "Messages without a matching method signature" "" { target *-*-* } 0 } */
440 /* { dg-warning "will be assumed to return .id. and accept" "" { target *-*-* } 0 } */
441 /* { dg-warning ".\.\.\.. as arguments" "" { target *-*-* } 0 } */