OpenCores
URL https://opencores.org/ocsvn/scarts/scarts/trunk

Subversion Repositories scarts

[/] [scarts/] [trunk/] [toolchain/] [scarts-gcc/] [gcc-4.1.1/] [gcc/] [testsuite/] [obj-c++.dg/] [class-protocol-1.mm] - Blame information for rev 12

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 12 jlechner
 
2
/* Check Class  types */
3
/* Author: David Ayers  */
4
/* { dg-do compile } */
5
 
6
#include 
7
#include 
8
 
9
@protocol MyProto1
10
+(void)doItClass1;
11
-(void)doItInstance1;
12
@end
13
 
14
@protocol MyProto2
15
+(void)doItClass2;
16
-(void)doItInstance2;
17
@end
18
 
19
@interface MyClass1 
20
{
21
  Class isa;
22
}
23
@end
24
@implementation MyClass1
25
+(void)doItClass1{}
26
-(void)doItInstance1{}
27
@end
28
 
29
@interface MyClass2 : MyClass1 
30
@end
31
@implementation MyClass2
32
+(void)doItClass2{}
33
-(void)doItInstance2{}
34
@end
35
 
36
@interface MyClass3
37
{
38
  Class isa;
39
}
40
@end
41
@interface MyClass4 : MyClass3 
42
@end
43
 
44
/*----------------------------------------*/
45
 
46
Class cls = 0;
47
Class  clsP1 = 0;
48
Class  clsP2 = 0;
49
 
50
void
51
testSimple(void)
52
{
53
  [cls doItClass1];
54
  [cls doItInstance1];
55
  [cls doItClass2];
56
  [cls doItInstance2];
57
 
58
  [clsP1 doItClass1];
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" } */
62
 
63
  [clsP2 doItClass1];    /* { dg-warning "not found in protocol" } */
64
  [clsP2 doItInstance1]; /* { dg-warning "not found in protocol" } */
65
  [clsP2 doItClass2];
66
  [clsP2 doItInstance2]; /* { dg-warning "instead of" }  */
67
 
68
  [MyClass1 doItClass1];
69
  [MyClass1 doItInstance1];
70
  [MyClass1 doItClass2];    /* { dg-warning "may not respond to" } */
71
  [MyClass1 doItInstance2]; /* { dg-warning "may not respond to" } */
72
 
73
  [MyClass2 doItClass1];
74
  [MyClass2 doItInstance1];
75
  [MyClass2 doItClass2];
76
  [MyClass2 doItInstance2]; /* { dg-warning "may not respond to" } */
77
 
78
  [MyClass3 doItClass1];    /* { dg-warning "may not respond to" } */
79
  [MyClass3 doItInstance1]; /* { dg-warning "may not respond to" } */
80
 
81
  [MyClass4 doItClass1];
82
  [MyClass4 doItInstance1]; /* { dg-warning "may not respond to" } */
83
}
84
 
85
/*----------------------------------------*/
86
/* Protocols declared by categories */
87
 
88
@protocol MyProto3
89
+(void)doItClass3;
90
-(void)doItInstance3;
91
@end
92
@protocol MyProto4
93
+(void)doItClass4;
94
-(void)doItInstance4;
95
@end
96
 
97
@interface MyClass1 (Category1) 
98
@end
99
@interface MyClass2 (Category2) 
100
@end
101
 
102
void
103
testCategory(void)
104
{
105
  [cls doItClass3];
106
  [cls doItInstance3];
107
  [cls doItClass4];
108
  [cls doItInstance4];
109
 
110
  [MyClass1 doItClass3];
111
  [MyClass1 doItInstance3];
112
  [MyClass1 doItClass4];    /* { dg-warning "may not respond" } */
113
  [MyClass1 doItInstance4]; /* { dg-warning "may not respond" } */
114
 
115
  [MyClass2 doItClass3];
116
  [MyClass2 doItInstance3];
117
  [MyClass2 doItClass4];
118
  [MyClass2 doItInstance4]; /* { dg-warning "may not respond" } */
119
 
120
}
121
 
122
/*----------------------------------------*/
123
/* Inherited protocols declared by categories */
124
 
125
@protocol MyProto5 
126
+(void)doItClass5;
127
-(void)doItInstance5;
128
@end
129
 
130
@protocol MyProto6 
131
+(void)doItClass6;
132
-(void)doItInstance6;
133
@end
134
 
135
@interface MyClass1 (Category3) 
136
@end
137
@interface MyClass2 (Category4) 
138
@end
139
 
140
Class  clsP5 = 0;
141
Class  clsP6 = 0;
142
 
143
void
144
testCategoryInherited(void)
145
{
146
  [cls doItClass5];
147
  [cls doItInstance5];
148
  [cls doItClass6];
149
  [cls doItInstance6];
150
 
151
  [clsP5 doItClass1];
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" } */
155
 
156
  [clsP6 doItClass1];    /* { dg-warning "not found in protocol" } */
157
  [clsP6 doItInstance1]; /* { dg-warning "not found in protocol" } */
158
  [clsP6 doItClass2];
159
  [clsP6 doItInstance2]; /* { dg-warning "instead of" }  */
160
 
161
 
162
  [MyClass1 doItClass5];
163
  [MyClass1 doItInstance5];
164
  [MyClass1 doItClass6];    /* { dg-warning "may not respond" } */
165
  [MyClass1 doItInstance6]; /* { dg-warning "may not respond" } */
166
 
167
  [MyClass2 doItClass5];
168
  [MyClass2 doItInstance5];
169
  [MyClass2 doItClass6];
170
  [MyClass2 doItInstance6]; /* { dg-warning "may not respond" } */
171
 
172
}
173
 
174
/*----------------------------------------*/
175
/* Forward declared root protocols */
176
 
177
@protocol FwProto;
178
 
179
@interface MyClass1 (Forward) 
180
@end
181
 
182
Class  clsP7 = 0;
183
 
184
void
185
testForwardeDeclared1(void)
186
{
187
  [cls doItClass7];         /* { dg-warning "no .\\+doItClass7. method found" } */
188
  [cls doItInstance7];      /* { dg-warning "no .\\+doItInstance7. method found" } */
189
 
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 } */
194
 
195
  [MyClass1 doItClass7];    /* { dg-warning "may not respond" } */
196
  [MyClass1 doItInstance7]; /* { dg-warning "may not respond" } */
197
 
198
  [MyClass2 doItClass7];    /* { dg-warning "may not respond" } */
199
  [MyClass2 doItInstance7]; /* { dg-warning "may not respond" } */
200
 
201
}
202
 
203
@protocol FwProto
204
+(void)doItClass7;
205
-(void)doItInstance7;
206
@end
207
 
208
void
209
testForwardeDeclared2(void)
210
{
211
  [cls doItClass7];
212
  [cls doItInstance7];
213
 
214
  [clsP7 doItClass7];
215
  [clsP7 doItInstance7]; /* { dg-warning "instead of" }  */
216
 
217
  [MyClass1 doItClass7];
218
  [MyClass1 doItInstance7];
219
 
220
  [MyClass2 doItClass7];
221
  [MyClass2 doItInstance7];
222
}
223
 
224
/*----------------------------------------*/
225
/* Inherited non root protocols */
226
 
227
@protocol MyProto8
228
+(void)doItClass8;
229
-(void)doItInstance8;
230
@end
231
 
232
@protocol MyProto9 
233
+(void)doItClass9;
234
-(void)doItInstance9;
235
@end
236
 
237
@interface MyClass1 (InheritedNonRoot) 
238
@end
239
 
240
Class  clsP8 = 0;
241
Class  clsP9 = 0;
242
 
243
void
244
testInheritedNonRoot(void)
245
{
246
  [cls doItClass8];
247
  [cls doItInstance8];
248
  [cls doItClass9];
249
  [cls doItInstance9];
250
 
251
  [clsP8 doItClass8];
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" } */
255
 
256
  [clsP9 doItClass8];
257
  [clsP9 doItInstance8]; /* { dg-warning "instead of" }  */
258
  [clsP9 doItClass9];
259
  [clsP9 doItInstance9]; /* { dg-warning "instead of" }  */
260
 
261
  [MyClass1 doItClass8];
262
  [MyClass1 doItInstance8];
263
  [MyClass1 doItClass9];
264
  [MyClass1 doItInstance9];
265
 
266
  [MyClass2 doItClass8];
267
  [MyClass2 doItInstance8];
268
  [MyClass2 doItClass9];
269
  [MyClass2 doItInstance9];
270
 
271
}
272
 
273
/*----------------------------------------*/
274
/* Prototype mismatch  */
275
 
276
@protocol MyOtherProto1
277
+(id)doItClass1;
278
-(id)doItInstance1;
279
@end
280
@interface MyOtherClass1 
281
@end
282
 
283
Class  oclsP1;
284
 
285
void
286
testPrototypeMismatch(void)
287
{
288
  id tmp1 = [oclsP1 doItClass1];
289
  id tmp2 = [oclsP1 doItInstance1]; /* { dg-warning "instead of" }  */
290
 
291
  [clsP1 doItClass1];
292
  [clsP1 doItInstance1]; /* { dg-warning "instead of" }  */
293
}
294
 
295
id obj = nil;
296
id  objP1 = nil;
297
id  objP2 = nil;
298
id  objP5 = nil;
299
int num = 0;
300
void *ptr = 0;
301
 
302
MyClass1 *mc1 = nil;
303
 
304
void
305
testComptypes(void)
306
{
307
  { /* id , id   */
308
    objP1 == objP2;  /* { dg-warning "lacks a cast" } */
309
    objP2 == objP1;  /* { dg-warning "lacks a cast" } */
310
 
311
    objP1 == objP5;
312
    objP5 == objP1;
313
  }
314
  { /* id , SomeClass *  */
315
    mc1 == objP1;
316
    objP1 == mc1;
317
 
318
    mc1 == objP2; /* { dg-warning "lacks a cast" } */
319
    objP2 == mc1; /* { dg-warning "lacks a cast" } */
320
  }
321
  { /* id , id  */
322
    obj == objP1;
323
    objP1 == obj;
324
  }
325
  { /* id , Class  */
326
    cls == objP1; /* { dg-warning "lacks a cast" } */
327
    objP1 == cls; /* { dg-warning "lacks a cast" } */
328
  }
329
  { /* id , non-ObjC  */
330
    num == objP1; /* { dg-warning "between pointer" } */
331
    objP1 == num; /* { dg-warning "between pointer" } */
332
 
333
    ptr == objP1;
334
    objP1 == ptr;
335
  }
336
  { /* Class , Class  */
337
    clsP1 == clsP2; /* { dg-warning "lacks a cast" } */
338
    clsP2 == clsP1; /* { dg-warning "lacks a cast" } */
339
 
340
    clsP1 == clsP5;
341
    clsP5 == clsP1;
342
  }
343
  { /* Class , SomeClass * */
344
    mc1 == clsP1; /* { dg-warning "lacks a cast" } */
345
    clsP1 == mc1; /* { dg-warning "lacks a cast" } */
346
  }
347
  { /* Class , id */
348
    obj == clsP1;
349
    clsP1 == obj;
350
  }
351
  { /* Class , Class */
352
    cls == clsP1;
353
    clsP1 == cls;
354
  }
355
  { /* Class , non-ObjC */
356
    num == clsP1; /* { dg-warning "between pointer" } */
357
    clsP1 == num; /* { dg-warning "between pointer" } */
358
 
359
    ptr == clsP1;
360
    clsP1 == ptr;
361
  }
362
  { /* Class , id  */
363
    clsP1 == objP1; /* { dg-warning "lacks a cast" } */
364
    objP1 == clsP1; /* { dg-warning "lacks a cast" } */
365
  }
366
 
367
  { /* id , id   */
368
    objP1 = objP2; /* { dg-warning "does not conform" } */
369
    objP2 = objP1; /* { dg-warning "does not conform" } */
370
 
371
    objP1 = objP5;
372
    objP5 = objP1; /* { dg-warning "does not conform" } */
373
  }
374
  { /* id , SomeClass *  */
375
    mc1 = objP1;
376
    objP1 = mc1;
377
 
378
    mc1 = objP2; /* { dg-warning "does not conform" } */
379
    objP2 = mc1; /* { dg-warning "does not implement" } */
380
  }
381
  { /* id , id  */
382
    obj = objP1;
383
    objP1 = obj;
384
  }
385
  { /* id , Class  */
386
    cls = objP1; /* { dg-warning "distinct Objective\\-C type" } */
387
    objP1 = cls; /* { dg-warning "distinct Objective\\-C type" } */
388
  }
389
  { /* id , non-ObjC  */
390
    num = objP1; /* { dg-error "invalid conversion" } */
391
    objP1 = num; /* { dg-error "invalid conversion" } */
392
 
393
    ptr = objP1;
394
    objP1 = ptr; /* { dg-error "invalid conversion" } */
395
  }
396
  { /* Class , Class  */
397
    clsP1 = clsP2; /* { dg-warning "does not conform" } */
398
    clsP2 = clsP1; /* { dg-warning "does not conform" } */
399
 
400
    clsP1 = clsP5;
401
    clsP5 = clsP1; /* { dg-warning "does not conform" } */
402
  }
403
  { /* Class , 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" } */
407
 
408
    mc1 = clsP2; /* { dg-warning "distinct Objective\\-C type" } */
409
    clsP2 = mc1; /* { dg-warning "distinct Objective\\-C type" } */
410
  }
411
  { /* Class , id */
412
    obj = clsP1;
413
    clsP1 = obj;
414
  }
415
  { /* Class , Class */
416
    cls = clsP1;
417
    clsP1 = cls;
418
  }
419
  { /* Class , non-ObjC */
420
    num = clsP1; /* { dg-error "invalid conversion" } */
421
    clsP1 = num; /* { dg-error "invalid conversion" } */
422
 
423
    ptr = clsP1;
424
    clsP1 = ptr; /* { dg-error "invalid conversion" } */
425
  }
426
  { /* Class , id  */
427
    clsP1 = objP1; /* { dg-warning "distinct Objective\\-C type" } */
428
    objP1 = clsP1; /* { dg-warning "distinct Objective\\-C type" } */
429
  }
430
}
431
 
432
int main ()
433
{
434
  testSimple();
435
  testCategory();
436
  testCategoryInherited();
437
  return(0);
438
}
439
 
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 } */

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.