summaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.dg/init/ref15.C
blob: bc9c01dc229bf72247589a6aa6ba73a3b2000b1f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// PR c++/20416.  We correctly constructed the temporary S in foo(),
// but incorrectly destroyed it every time foo() was called.
// When using a wrapped target, there is no way to override the exit
// code after returning from main.
// { dg-do run { target unwrapped } }
extern "C" void abort (void);
extern "C" void _exit (int);

int c, exiting;
struct S {
  S() { ++c; }
  S(const S &) { ++c; }
  ~S()
  {
    if (!exiting) abort ();
    _exit (0);
  }
};
void
foo (void)
{
  static const S &s = S();
}
int main ()
{
  if (c != 0)
    abort ();
  foo ();
  foo ();
  if (c != 1)
    abort ();
  exiting = 1;
  return 1;
}