2007-03-01 Paul Brook <paul@codesourcery.com>
[official-gcc.git] / gcc / testsuite / objc.dg / lookup-1.m
blob71fc61ea04ef9cdaa0442d0bce0b7597fe46a220
1 /* { dg-do run { target *-*-darwin* } } */
3 #include <objc/Object.h>
4 #include <stdlib.h>
6 typedef struct MyWidget {
7   int a;
8 } MyWidget;
10 MyWidget gWidget = { 17 };
12 @protocol MyProto
13 - (MyWidget *)widget;
14 @end
16 @interface Foo: Object
17 @end
19 @interface Bar: Foo <MyProto>
20 @end
22 @interface Container: Object
23 + (MyWidget *)elementForView:(Foo *)view;
24 @end
26 @implementation Foo
27 @end
29 @implementation Bar
30 - (MyWidget *)widget {
31   return &gWidget;
33 @end
35 @implementation Container
36 + (MyWidget *)elementForView:(Foo *)view
38   MyWidget *widget = nil;
39   if ([view conformsTo:@protocol(MyProto)]) {
40     widget = [(Foo <MyProto> *)view widget];
41   }
42   return widget;
44 @end
46 int main(void) {
47   id view = [Bar new];
48   MyWidget *w = [Container elementForView: view];
50   if (!w || w->a != 17)
51     abort ();
53   return 0;