aboutsummaryrefslogtreecommitdiffstats
path: root/gcc-4.4.3/gcc/testsuite/g++.dg/init/ref15.C
blob: d3a94227fd0b9d1217b2d1a493f4960760fa6ea5 (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
// PR c++/20416.  We correctly constructed the temporary S in foo(),
// but incorrectly destroyed it every time foo() was called.
// { dg-do run }
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;
}