d3a94227fd0b9d1217b2d1a493f4960760fa6ea5
[gcc.git] / gcc / testsuite / g++.dg / init / ref15.C
1 // PR c++/20416. We correctly constructed the temporary S in foo(),
2 // but incorrectly destroyed it every time foo() was called.
3 // { dg-do run }
4 extern "C" void abort (void);
5 extern "C" void _exit (int);
6
7 int c, exiting;
8 struct S {
9 S() { ++c; }
10 S(const S &) { ++c; }
11 ~S()
12 {
13 if (!exiting) abort ();
14 _exit (0);
15 }
16 };
17 void
18 foo (void)
19 {
20 static const S &s = S();
21 }
22 int main ()
23 {
24 if (c != 0)
25 abort ();
26 foo ();
27 foo ();
28 if (c != 1)
29 abort ();
30 exiting = 1;
31 return 1;
32 }