summaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.dg/init/delete2.C
blob: 8a486beaa5a22a8799b0f746f229f6089d6c962c (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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// PR c++/15097
// { dg-do run }

typedef __SIZE_TYPE__ size_t;

extern "C" void * malloc (size_t);
extern "C" void free (void *);
extern "C" void abort(void);

void *saved;

void * operator new (size_t size)
{
  void *p = malloc (size);
  saved = p;
  return p;
}

void operator delete (void *p)
{
  if (p != saved)
    abort ();
  free (p);
}

struct B1
{
    virtual ~B1 () throw() {}
    B1 (){}
    int x;
};
struct B2
{
    virtual ~B2 () throw() {}
    B2 (){}
    int x;
};
struct D : B1, B2
{
    D (){}
    ~D () throw() {}
    int y;
};
void f1 (D*);
void f2 (B2*);
void f3 (B1*);
int main (void)
{
    f1 (::new D);
    f2 (::new D);     
    f3 (::new D);
}
void f1 ( D* p) { ::delete p; }
void f2 (B2* p) { ::delete p; }  
void f3 (B1* p) { ::delete p; }