1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <new>
4 
5 int pass = 0;
6 
7 void *
operator new(size_t sz,const std::nothrow_t &)8 operator new (size_t sz, const std::nothrow_t&) throw ()
9 {
10   void *p;
11   pass++;
12   p = malloc(sz);
13   return p;
14 }
15 
16 void *
operator new(size_t sz)17 operator new (size_t sz) throw (std::bad_alloc)
18 {
19   void *p;
20   pass++;
21   p = malloc(sz);
22   return p;
23 }
24 
25 void
operator delete(void * ptr)26 operator delete (void *ptr) throw ()
27 {
28   pass++;
29   if (ptr)
30     free (ptr);
31 }
32 
33 class A
34 {
35 public:
A()36   A() {}
~A()37   ~A() { }
38   int a;
39   int b;
40 };
41 
42 
43 int
main(void)44 main (void)
45 {
46   A *bb = new A[10];
47   delete [] bb;
48   bb = new (std::nothrow) A [10];
49   delete [] bb;
50 
51   if (pass == 4)
52     {
53       printf ("PASS\n");
54       return 0;
55     }
56   else
57     {
58       printf ("FAIL\n");
59       return 1;
60     }
61 }
62