OSDN Git Service

cp/ChangeLog
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / g++.old-deja / g++.other / init19.C
1 // { dg-do run { xfail { { ! cxa_atexit } && { ! { mips-sgi-irix* *-*-solaris2* } } } } }
2 #include <stdlib.h>
3
4 #define assert(x) do { if (! (x)) abort(); } while (0)
5
6 int count = 0;
7
8 class A
9 {
10 public:
11         explicit A(int i);
12         ~A();
13
14         int i;
15
16         A(const A&);
17         A& operator=(const A&);
18 };
19
20 A::A(int i_)
21         : i(i_)
22 {
23 }
24
25 A::~A()
26 {
27         assert(++count == i);
28         i = -1;
29 }
30
31 extern "C" {
32
33 void one()
34 {
35         static bool second_time;
36         if (second_time)
37                 assert(++count == 9);
38         else
39         {
40                 assert(++count == 1);
41                 second_time = true;
42         }
43         static A a(10);
44         assert(a.i == 10);
45 }
46
47 void two()
48 {
49         assert(++count == 7);
50         static A a(8);
51         assert(a.i == 8);
52 }
53
54 void three()
55 {
56         assert(++count == 2);
57         static A a(6);
58         assert(a.i == 6);
59 }
60
61 void five()
62 {
63         assert(++count == 4);
64         static A a(5);
65         assert(a.i == 5);
66 }
67
68 void four()
69 {
70         assert(++count == 3);
71         atexit(five);
72 }
73
74 }
75
76 A zero(11);
77
78 int main()
79 {
80         one();
81         atexit(one);
82         atexit(two);
83         three();
84         atexit(four);
85 }