OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-old/] [gcc-4.2.2/] [gcc/] [testsuite/] [obj-c++.dg/] [cxx-ivars-2.mm] - Blame information for rev 823

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 149 jeremybenn
// Check if the '- .cxx_construct' and '-.cxx_destruct' methods get called
2
// and if they perform their desired function.
3
 
4
// { dg-do run }
5
// { dg-options "-fobjc-call-cxx-cdtors" }
6
 
7
#include 
8
#include 
9
#define CHECK_IF(expr) if(!(expr)) abort()
10
 
11
static int ctor1_called, ctor2_called, dtor1_called;
12
 
13
struct bar {
14
  int a, b;
15
  bar(void) {
16
    a = 5; b = 6;
17
    ctor1_called++;
18
  }
19
  ~bar(void) {
20
    a = b = 99;
21
    dtor1_called++;
22
  }
23
};
24
 
25
struct boo: bar {
26
  int c;
27
  boo(int _c = 9): c(_c) {
28
    ctor2_called++;
29
  }
30
};
31
 
32
@interface Baz: Object {
33
@public
34
  bar aa;
35
}
36
@end
37
 
38
@implementation Baz
39
@end
40
 
41
@interface Foo: Baz {
42
@public
43
  int a;
44
  boo bb;
45
  bar b;
46
  float c;
47
  bar d;
48
}
49
@end
50
 
51
@implementation Foo
52
@end
53
 
54
int main (void)
55
{
56
  CHECK_IF(!ctor1_called && !ctor2_called && !dtor1_called); /* are we sane? */
57
 
58
  Baz *baz = [Baz new];
59
  CHECK_IF(ctor1_called && !ctor2_called && !dtor1_called);
60
  CHECK_IF(baz->aa.a == 5 && baz->aa.b == 6);
61
  ctor1_called = 0;  /* reset */
62
 
63
  [baz free];
64
  CHECK_IF(!ctor1_called && !ctor2_called && dtor1_called);
65
  dtor1_called = 0;  /* reset */
66
 
67
  Foo *foo = [Foo new];
68
  CHECK_IF(ctor1_called && ctor2_called && !dtor1_called);
69
  CHECK_IF(foo->bb.a == 5 && foo->bb.b == 6 && foo->bb.c == 9);
70
  CHECK_IF(foo->b.a == 5 && foo->b.b == 6);
71
  CHECK_IF(foo->d.a == 5 && foo->d.b == 6);
72
  ctor1_called = ctor2_called = 0;  /* reset */
73
 
74
  [foo free];
75
  CHECK_IF(!ctor1_called && !ctor2_called && dtor1_called);
76
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.