OSDN Git Service

* objc.dg/stret-1.m (glob): Renamed to globa.
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / objc.dg / stret-1.m
1 /* Test for handling of struct-returning methods.  */
2 /* Contributed by Ziemowit Laski <zlaski@apple.com>.  */
3 /* { dg-do run } */
4
5 #include <objc/Object.h>
6
7 extern void abort(void);
8 #define CHECK_IF(expr) if(!(expr)) abort()
9
10 struct astruct {
11   float a, b;
12 } globa = { 1.0, 2.0 };
13
14 struct bstruct {
15   float a, b, c, d, e, f;
16 } globb = { 1, 2, 3, 4, 5, 6 };
17
18 @interface foo : Object
19 - (struct astruct) stret;
20 - (struct bstruct) stretb;
21 @end
22
23 @implementation foo : Object
24 - (struct astruct) stret { return globa; }
25 - (struct bstruct) stretb { return globb; }
26 @end
27
28 @interface bar: foo
29 - (struct astruct) stret;
30 - (struct bstruct) stretb;
31 @end
32
33 @implementation bar
34 - (struct astruct) stret { struct astruct a = [super stret]; a.b = 77; return a; }
35 - (struct bstruct) stretb { struct bstruct b = [super stretb]; b.e = 99; return b; }
36 @end
37
38 int main(void)
39 {
40   foo *obj = [foo new];
41   bar *obj2 = [bar new];
42   struct astruct loc, loc2;
43   struct bstruct locb, locb2;
44
45   loc = [obj stret];
46   CHECK_IF(loc.a == 1.0 && loc.b == 2.0);
47
48   locb = [obj stretb];
49   CHECK_IF(locb.f == 6 && locb.c == 3);
50   CHECK_IF(locb.e == 5 && locb.b == 2);
51   CHECK_IF(locb.d == 4 && locb.a == 1);
52
53   loc2 = [obj2 stret];
54   CHECK_IF(loc2.a == 1.0 && loc2.b == 77);
55   
56   locb2 = [obj2 stretb];
57   CHECK_IF(locb2.f == 6 && locb2.c == 3);
58   CHECK_IF(locb2.e == 99 && locb2.b == 2);
59   CHECK_IF(locb2.d == 4 && locb2.a == 1);
60   
61   return 0;
62 }