njn | 734b805 | 2007-11-01 04:40:37 +0000 | [diff] [blame] | 1 | // operator new(unsigned) |
| 2 | // operator new[](unsigned) |
| 3 | // operator new(unsigned, std::nothrow_t const&) |
| 4 | // operator new[](unsigned, std::nothrow_t const&) |
| 5 | |
| 6 | #include <stdlib.h> |
| 7 | |
| 8 | #include <new> |
| 9 | |
| 10 | using std::nothrow_t; |
| 11 | |
| 12 | // A big structure. Its details don't matter. |
sewardj | 6657109 | 2007-11-03 11:16:31 +0000 | [diff] [blame] | 13 | typedef struct { |
| 14 | int array[1000]; |
| 15 | } s; |
njn | 734b805 | 2007-11-01 04:40:37 +0000 | [diff] [blame] | 16 | |
sewardj | 764b604 | 2008-11-08 15:01:22 +0000 | [diff] [blame] | 17 | __attribute__((noinline)) void* operator new (std::size_t n) throw (std::bad_alloc) |
njn | 734b805 | 2007-11-01 04:40:37 +0000 | [diff] [blame] | 18 | { |
| 19 | return malloc(n); |
| 20 | } |
| 21 | |
sewardj | 764b604 | 2008-11-08 15:01:22 +0000 | [diff] [blame] | 22 | __attribute__((noinline)) void* operator new (std::size_t n, std::nothrow_t const &) throw () |
njn | 734b805 | 2007-11-01 04:40:37 +0000 | [diff] [blame] | 23 | { |
| 24 | return malloc(n); |
| 25 | } |
| 26 | |
sewardj | 764b604 | 2008-11-08 15:01:22 +0000 | [diff] [blame] | 27 | __attribute__((noinline)) void* operator new[] (std::size_t n) throw (std::bad_alloc) |
njn | 734b805 | 2007-11-01 04:40:37 +0000 | [diff] [blame] | 28 | { |
| 29 | return malloc(n); |
| 30 | } |
| 31 | |
sewardj | 764b604 | 2008-11-08 15:01:22 +0000 | [diff] [blame] | 32 | __attribute__((noinline)) void* operator new[] (std::size_t n, std::nothrow_t const &) throw () |
njn | 734b805 | 2007-11-01 04:40:37 +0000 | [diff] [blame] | 33 | { |
| 34 | return malloc(n); |
| 35 | } |
| 36 | |
florian | 629b4dc | 2013-10-01 22:18:14 +0000 | [diff] [blame] | 37 | __attribute__((noinline)) void operator delete (void* p) throw() |
njn | 734b805 | 2007-11-01 04:40:37 +0000 | [diff] [blame] | 38 | { |
| 39 | return free(p); |
| 40 | } |
| 41 | |
florian | 629b4dc | 2013-10-01 22:18:14 +0000 | [diff] [blame] | 42 | __attribute__((noinline)) void operator delete[] (void* p) throw() |
njn | 734b805 | 2007-11-01 04:40:37 +0000 | [diff] [blame] | 43 | { |
| 44 | return free(p); |
| 45 | } |
| 46 | |
| 47 | int main(void) |
| 48 | { |
sewardj | 6657109 | 2007-11-03 11:16:31 +0000 | [diff] [blame] | 49 | s* p1 = new s; |
| 50 | s* p2 = new (std::nothrow) s; |
njn | 734b805 | 2007-11-01 04:40:37 +0000 | [diff] [blame] | 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; |
| 58 | } |
| 59 | |
| 60 | |