1 #include <stdio.h>
2 
3 // PR c++/15097
4 // { dg-do run }
5 
6 typedef __SIZE_TYPE__ size_t;
7 
8 extern "C" void * malloc (size_t);
9 extern "C" void free (void *);
10 extern "C" void abort(void);
11 
12 void *saved;
13 
operator new(size_t size)14 void * operator new (size_t size)
15 {
16   void *p = malloc (size);
17   saved = p;
18   return p;
19 }
20 
operator delete(void * p)21 void operator delete (void *p)
22 {
23 // Note that since STL is built w/o -Bsymbolic a lots of other code in STL
24 // may use the customized new/delete in this file.  We only save one copy of
25 // poitner in variable "saved", but because this testcase new and immediately
26 // delete in single thread, this single-copy serves well, provided that we only
27 // check saved==p once and set saved to NULL to prevent further comparison of
28 // unrelated delete from within STL
29   if (saved) {
30      if (p == saved) {
31         saved = NULL;
32      } else {
33         abort ();
34      }
35   }
36 
37   free (p);
38 }
39 
40 struct B1
41 {
~B1B142     virtual ~B1 () throw() {}
B1B143     B1 (){}
44     int x;
45 };
46 struct B2
47 {
~B2B248     virtual ~B2 () throw() {}
B2B249     B2 (){}
50     int x;
51 };
52 struct D : B1, B2
53 {
DD54     D (){}
~DD55     ~D () throw() {}
56     int y;
57 };
58 void f1 (D*);
59 void f2 (B2*);
60 void f3 (B1*);
main(void)61 int main (void)
62 {
63     f1 (::new D);
64     f2 (::new D);
65     f3 (::new D);
66 }
f1(D * p)67 void f1 ( D* p) { ::delete p; }
f2(B2 * p)68 void f2 (B2* p) { ::delete p; }
f3(B1 * p)69 void f3 (B1* p) { ::delete p; }
70