drd: Improve thread startup code for non-Linux platforms
[valgrind.git] / massif / tests / overloaded-new.cpp
blob6c61d8e1d5efa59994af0c9512f1191022363b6f
1 // operator new(unsigned)
2 // operator new[](unsigned)
3 // operator new(unsigned, std::nothrow_t const&)
4 // operator new[](unsigned, std::nothrow_t const&)
6 #include <stdlib.h>
8 #include <new>
10 using std::nothrow_t;
12 // A big structure. Its details don't matter.
13 typedef struct {
14 int array[1000];
15 } s;
17 __attribute__((noinline)) void* operator new (std::size_t n) throw (std::bad_alloc)
19 return malloc(n);
22 __attribute__((noinline)) void* operator new (std::size_t n, std::nothrow_t const &) throw ()
24 return malloc(n);
27 __attribute__((noinline)) void* operator new[] (std::size_t n) throw (std::bad_alloc)
29 return malloc(n);
32 __attribute__((noinline)) void* operator new[] (std::size_t n, std::nothrow_t const &) throw ()
34 return malloc(n);
37 __attribute__((noinline)) void operator delete (void* p) throw()
39 return free(p);
42 __attribute__((noinline)) void operator delete[] (void* p) throw()
44 return free(p);
47 int main(void)
49 s* p1 = new s;
50 s* p2 = new (std::nothrow) s;
51 char* c1 = new char[2000];
52 char* c2 = new (std::nothrow) char[2000];
53 delete p1;
54 delete p2;
55 delete [] c1;
56 delete [] c2;
57 return 0;