OSDN Git Service

* objc.dg/comp-types-8.m, objc.dg/encode-6.m,
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / objc.dg / lookup-1.m
1 /* { dg-do run } */
2
3 #include <objc/Object.h>
4 #include <stdlib.h>
5
6 typedef struct MyWidget {
7   int a;
8 } MyWidget;
9
10 MyWidget gWidget = { 17 };
11
12 @protocol MyProto
13 - (MyWidget *)widget;
14 @end
15
16 @interface Foo: Object
17 @end
18
19 @interface Bar: Foo <MyProto>
20 @end
21
22 @interface Container: Object
23 + (MyWidget *)elementForView:(Foo *)view;
24 @end
25
26 @implementation Foo
27 @end
28
29 @implementation Bar
30 - (MyWidget *)widget {
31   return &gWidget;
32 }
33 @end
34
35 @implementation Container
36 + (MyWidget *)elementForView:(Foo *)view
37 {
38   MyWidget *widget = nil;
39   if ([view conformsTo:@protocol(MyProto)]) {
40     widget = [(Foo <MyProto> *)view widget];
41   }
42   return widget;
43 }
44 @end
45
46 int main(void) {
47   id view = [Bar new];
48   MyWidget *w = [Container elementForView: view];
49
50   if (!w || w->a != 17)
51     abort ();
52
53   return 0;
54 }