Back to index

cell-binutils  2.17cvs20070401
dl5.cc
Go to the documentation of this file.
00001 #include <stdio.h>
00002 #include <stdlib.h>
00003 #include <new>
00004 
00005 int pass = 0;
00006 
00007 void *
00008 operator new (size_t sz, const std::nothrow_t&) throw ()
00009 {
00010   void *p;
00011   pass++;
00012   p = malloc(sz);
00013   return p;
00014 }
00015 
00016 void *
00017 operator new (size_t sz) throw (std::bad_alloc)
00018 {
00019   void *p;
00020   pass++;
00021   p = malloc(sz);
00022   return p;
00023 }
00024 
00025 void
00026 operator delete (void *ptr) throw ()
00027 {
00028   pass++;
00029   if (ptr)
00030     free (ptr);
00031 }
00032 
00033 class A 
00034 {
00035 public:
00036   A() {}
00037   ~A() { }
00038   int a;
00039   int b;
00040 };
00041 
00042 
00043 int
00044 main (void)
00045 {
00046   A *bb = new A[10];
00047   delete [] bb;
00048   bb = new (std::nothrow) A [10];
00049   delete [] bb;
00050 
00051   if (pass == 4)
00052     {
00053       printf ("PASS\n");
00054       return 0;
00055     }
00056   else
00057     {
00058       printf ("FAIL\n");
00059       return 1;
00060     }
00061 }