OSDN Git Service

bccf4a1123357af7148a80c112d82c235e88cb16
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / objc.dg / torture / forward-1.m
1 /* { dg-do run } */
2 /* See if -forward::/-performv:: is able to work. */
3 /* { dg-xfail-run-if "PR36610" { ! { { i?86-*-* x86_64-*-* } && ilp32 } } { "-fgnu-runtime" } { "" } } */
4 /* { dg-skip-if "Needs OBJC2 Implementation" { *-*-darwin* && { lp64 } } { "-fnext-runtime" } { "" } } */
5 /* There is no implementation of forward: in the NeXT m64 libobjc/Object
6    neither have we implemented this in our extensions - so we have to skip it
7    for now.  */
8
9 #include <stdio.h>
10 #include <stdlib.h>
11
12 #ifndef __NEXT_RUNTIME__
13 #  include <objc/objc-api.h>
14 #endif
15 #include <objc/Object.h>
16
17 #define VALUETOUSE 1234567890
18
19 id forwarder, receiver;
20
21 @interface Forwarder: Object
22 {
23     id receiver;
24 }
25
26 -initWithReceiver:theReceiver;
27
28 @end
29
30 @interface Receiver:Object
31 {
32     int foo;
33 }
34 -display;
35 -initWithFoo:(int)theFoo;
36 @end
37 @implementation Receiver
38
39 -initWithFoo: (int)theFoo
40 {
41     foo = theFoo;
42     return self;
43 }
44
45 -display
46 {
47     /* Check to see if we are really the reciever. */
48     if (self != receiver)
49         abort ();
50     /* And the value of foo is set correctly. */
51     if (foo != VALUETOUSE)
52       abort ();
53     return self;
54 }
55
56 @end
57
58 @implementation Forwarder
59 -initWithReceiver: theReceiver
60 {
61     [super init];
62     receiver = theReceiver;
63     return self;
64 }
65 #ifdef __NEXT_RUNTIME__
66 - forward: (SEL)theSel: (marg_list)theArgFrame
67 #else
68 -(retval_t) forward: (SEL)theSel: (arglist_t)theArgFrame
69 #endif
70 {
71   /* If we have a reciever try to perform on that object */
72     if (receiver)
73         return [receiver performv: theSel: theArgFrame];
74     return [self doesNotRecognize:theSel];
75 }
76 @end
77 int main()
78 {
79     /* Init the reciever. */
80     receiver = [[Receiver alloc] initWithFoo: VALUETOUSE];
81     /* Init the fowarder. */
82     forwarder = [[Forwarder alloc] initWithReceiver: receiver];
83     /* Call display on the forwarder which in turns calls display on
84        the reciever. */
85     [forwarder display];
86     exit(0);
87 }