OSDN Git Service

Add NIOS2 support. Code from SourceyG++.
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / obj-c++.dg / cxx-ivars-2.mm
1 // Check if the '- .cxx_construct' and '-.cxx_destruct' methods get called
2 // and if they perform their desired function.
3
4 // { dg-xfail-run-if "PR27247/PR23681" { *-*-* } { "-fgnu-runtime" } { "" } }
5 // { dg-xfail-run-if "Needs OBJC2 ABI" { *-*-darwin* && { lp64 && { ! objc2 } } } { "-fnext-runtime" } { "" } }
6 // { dg-options "-fobjc-call-cxx-cdtors" }
7
8 #include "../objc-obj-c++-shared/Object1.h"
9 #include <stdlib.h>
10 #define CHECK_IF(expr) if(!(expr)) abort()
11
12 static int ctor1_called, ctor2_called, dtor1_called;
13
14 struct bar {
15   int a, b;
16   bar(void) {
17     a = 5; b = 6;
18     ctor1_called++;
19   }
20   ~bar(void) {
21     a = b = 99;
22     dtor1_called++;
23   }
24 };
25
26 struct boo: bar {
27   int c;
28   boo(int _c = 9): c(_c) {
29     ctor2_called++;
30   }
31 };
32
33 @interface Baz: Object {
34 @public
35   bar aa;
36 }
37 @end
38
39 @implementation Baz
40 @end
41
42 @interface Foo: Baz {
43 @public
44   int a;
45   boo bb;
46   bar b;
47   float c;
48   bar d;
49 }
50 @end
51
52 @implementation Foo
53 @end
54
55 int main (void)
56 {
57   CHECK_IF(!ctor1_called && !ctor2_called && !dtor1_called); /* are we sane? */
58
59   Baz *baz = [Baz new];
60   CHECK_IF(ctor1_called && !ctor2_called && !dtor1_called);
61   CHECK_IF(baz->aa.a == 5 && baz->aa.b == 6);
62   ctor1_called = 0;  /* reset */
63   
64   [baz free];
65   CHECK_IF(!ctor1_called && !ctor2_called && dtor1_called);
66   dtor1_called = 0;  /* reset */
67
68   Foo *foo = [Foo new];
69   CHECK_IF(ctor1_called && ctor2_called && !dtor1_called);
70   CHECK_IF(foo->bb.a == 5 && foo->bb.b == 6 && foo->bb.c == 9);
71   CHECK_IF(foo->b.a == 5 && foo->b.b == 6);
72   CHECK_IF(foo->d.a == 5 && foo->d.b == 6);
73   ctor1_called = ctor2_called = 0;  /* reset */
74   
75   [foo free];
76   CHECK_IF(!ctor1_called && !ctor2_called && dtor1_called);
77 }
78 #include "../objc-obj-c++-shared/Object1-implementation.h"