blob: e92cfd55a1cf9c29d6cd39789b1858b2c6ccff13 [file] [log] [blame]
njn734b8052007-11-01 04:40:37 +00001// 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
10using std::nothrow_t;
11
12// A big structure. Its details don't matter.
sewardj66571092007-11-03 11:16:31 +000013typedef struct {
14 int array[1000];
15 } s;
njn734b8052007-11-01 04:40:37 +000016
sewardj764b6042008-11-08 15:01:22 +000017__attribute__((noinline)) void* operator new (std::size_t n) throw (std::bad_alloc)
njn734b8052007-11-01 04:40:37 +000018{
19 return malloc(n);
20}
21
sewardj764b6042008-11-08 15:01:22 +000022__attribute__((noinline)) void* operator new (std::size_t n, std::nothrow_t const &) throw ()
njn734b8052007-11-01 04:40:37 +000023{
24 return malloc(n);
25}
26
sewardj764b6042008-11-08 15:01:22 +000027__attribute__((noinline)) void* operator new[] (std::size_t n) throw (std::bad_alloc)
njn734b8052007-11-01 04:40:37 +000028{
29 return malloc(n);
30}
31
sewardj764b6042008-11-08 15:01:22 +000032__attribute__((noinline)) void* operator new[] (std::size_t n, std::nothrow_t const &) throw ()
njn734b8052007-11-01 04:40:37 +000033{
34 return malloc(n);
35}
36
sewardj764b6042008-11-08 15:01:22 +000037__attribute__((noinline)) void operator delete (void* p)
njn734b8052007-11-01 04:40:37 +000038{
39 return free(p);
40}
41
sewardj764b6042008-11-08 15:01:22 +000042__attribute__((noinline)) void operator delete[] (void* p)
njn734b8052007-11-01 04:40:37 +000043{
44 return free(p);
45}
46
47int main(void)
48{
sewardj66571092007-11-03 11:16:31 +000049 s* p1 = new s;
50 s* p2 = new (std::nothrow) s;
njn734b8052007-11-01 04:40:37 +000051 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