aboutsummaryrefslogtreecommitdiffstats
path: root/gcc-4.9/gcc/testsuite/g++.old-deja/g++.jason/dtor5.C
blob: 3cf1d1cd0e2763cb863a39f31d25200fc3262cd3 (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
// { dg-do run  }
// PRMS Id: 5286
// Bug: g++ forgets side-effects of object in call to nonexistent destructor.

#include <new>

int r;

template <class T> struct A {
  T *p;
  int i;
  A() { i = 0; p = (T*) new char[sizeof (T)]; new (p + i++) T; }
  ~A() { p[--i].~T(); r = i; }
};

int main()
{
  { A<int> a; }

  int* p = (int*) new char[sizeof (int)];
  new (p + r++) int;
  typedef int I;
  p[--r].~I();
  
  return r;
}