Home | History | Annotate | Download | only in jni
      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 
     14 void * operator new (size_t size)
     15 {
     16   void *p = malloc (size);
     17   saved = p;
     18   return p;
     19 }
     20 
     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 {
     42     virtual ~B1 () throw() {}
     43     B1 (){}
     44     int x;
     45 };
     46 struct B2
     47 {
     48     virtual ~B2 () throw() {}
     49     B2 (){}
     50     int x;
     51 };
     52 struct D : B1, B2
     53 {
     54     D (){}
     55     ~D () throw() {}
     56     int y;
     57 };
     58 void f1 (D*);
     59 void f2 (B2*);
     60 void f3 (B1*);
     61 int main (void)
     62 {
     63     f1 (::new D);
     64     f2 (::new D);
     65     f3 (::new D);
     66 }
     67 void f1 ( D* p) { ::delete p; }
     68 void f2 (B2* p) { ::delete p; }
     69 void f3 (B1* p) { ::delete p; }
     70