OSDN Git Service

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