reflect: canonicalize types returned by StructOf() and friends
[official-gcc.git] / gcc / testsuite / obj-c++.dg / cxx-ivars-2.mm
blob22ab118df822baa67599dc26f19239a7d03faf0f
1 // Check if the '- .cxx_construct' and '-.cxx_destruct' methods get called
2 // and if they perform their desired function.
4 // { dg-xfail-run-if "Needs OBJC2 ABI" { *-*-darwin* && { lp64 && { ! objc2 } } } { "-fnext-runtime" } { "" } }
5 // { dg-do run { target *-*-darwin* } }
6 // { dg-skip-if "" { *-*-* } { "-fgnu-runtime" } { "" } }
7 // { dg-options "-fobjc-call-cxx-cdtors" }
9 #include "../objc-obj-c++-shared/TestsuiteObject.m"
10 #include <stdlib.h>
11 #define CHECK_IF(expr) if(!(expr)) abort()
13 static int ctor1_called, ctor2_called, dtor1_called;
15 struct bar {
16   int a, b;
17   bar(void) {
18     a = 5; b = 6;
19     ctor1_called++;
20   }
21   ~bar(void) {
22     a = b = 99;
23     dtor1_called++;
24   }
27 struct boo: bar {
28   int c;
29   boo(int _c = 9): c(_c) {
30     ctor2_called++;
31   }
34 @interface Baz: TestsuiteObject {
35 @public
36   bar aa;
38 @end
40 @implementation Baz
41 @end
43 @interface Foo: Baz {
44 @public
45   int a;
46   boo bb;
47   bar b;
48   float c;
49   bar d;
51 @end
53 @implementation Foo
54 @end
56 int main (void)
58   CHECK_IF(!ctor1_called && !ctor2_called && !dtor1_called); /* are we sane? */
60   Baz *baz = [Baz new];
61   CHECK_IF(ctor1_called && !ctor2_called && !dtor1_called);
62   CHECK_IF(baz->aa.a == 5 && baz->aa.b == 6);
63   ctor1_called = 0;  /* reset */
64   
65   [baz free];
66   CHECK_IF(!ctor1_called && !ctor2_called && dtor1_called);
67   dtor1_called = 0;  /* reset */
69   Foo *foo = [Foo new];
70   CHECK_IF(ctor1_called && ctor2_called && !dtor1_called);
71   CHECK_IF(foo->bb.a == 5 && foo->bb.b == 6 && foo->bb.c == 9);
72   CHECK_IF(foo->b.a == 5 && foo->b.b == 6);
73   CHECK_IF(foo->d.a == 5 && foo->d.b == 6);
74   ctor1_called = ctor2_called = 0;  /* reset */
75   
76   [foo free];
77   CHECK_IF(!ctor1_called && !ctor2_called && dtor1_called);