Merged r157653 through r157895 into branch.
[official-gcc.git] / gcc / testsuite / objc.dg / lookup-1.m
blobff59b7efba98fa20168d6d5832e402febff46e06
1 /* { dg-do run } */
2 /* { dg-xfail-run-if "Needs OBJC2 ABI" { *-*-darwin* && { lp64 && { ! objc2 } } } { "-fnext-runtime" } { "" } } */
4 #include <stdlib.h>
5 #include "../objc-obj-c++-shared/Object1.h"
7 typedef struct MyWidget {
8   int a;
9 } MyWidget;
11 MyWidget gWidget = { 17 };
13 @protocol MyProto
14 - (MyWidget *)widget;
15 @end
17 @interface Foo: Object
18 @end
20 @interface Bar: Foo <MyProto>
21 @end
23 @interface Container: Object
24 + (MyWidget *)elementForView:(Foo *)view;
25 @end
27 @implementation Foo
28 @end
30 @implementation Bar
31 - (MyWidget *)widget {
32   return &gWidget;
34 @end
36 @implementation Container
37 + (MyWidget *)elementForView:(Foo *)view
39   MyWidget *widget = (MyWidget *) nil;
40   if ([view conformsTo:@protocol(MyProto)]) {
41     widget = [(Foo <MyProto> *)view widget];
42   }
43   return widget;
45 @end
47 int main(void) {
48   id view = [Bar new];
49   MyWidget *w = [Container elementForView: view];
51   if (!w || w->a != 17)
52     abort ();
54   return 0;
57 #include "../objc-obj-c++-shared/Object1-implementation.h"