summaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.old-deja/g++.other/delete8.C
blob: ea44445b0b6c06b63c0256df3d09ce69c7bceb0b (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
35
36
37
38
39
40
// { dg-do run  }
// Origin: Mark Mitchell <mark@codesourcery.com>

#include <stdlib.h>

struct S {
  ~S ();
};

bool flag;
S* s1;
S* s2;

void* operator new (size_t s)
{
  return malloc (s);
}

void operator delete (void* p)
{
  if (flag && p != s2)
    abort ();
}

S::~S () { 
  if (this != s2)
    abort ();
  s1 = 0;
}

int main () {
  s2 = new S;
  s1 = s2;
  // Turn on the check in `operator delete'.
  flag = true;
  delete s1;
  // Turn it off again so that normal shutdown code works.
  flag = false;
}