coregrind/m_gdbserver/remote-utils.c (prepare_resume_reply): Use memcpy
[valgrind.git] / massif / tests / overloaded-new.cpp
blob5ad92894e9d66ced732c2461d22e135892f42ff3
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)
19 return (void*)12345;
22 __attribute__((noinline)) void* operator new (std::size_t n, std::nothrow_t const &)
24 return (void*)23456;
27 __attribute__((noinline)) void* operator new[] (std::size_t n)
29 return (void*)34567;
32 __attribute__((noinline)) void* operator new[] (std::size_t n, std::nothrow_t const &)
34 return (void*)45678;
37 __attribute__((noinline)) void* operator new (std::size_t size, std::align_val_t al)
39 return (void*)56789;
42 __attribute__((noinline)) void* operator new[] (std::size_t size, std::align_val_t al)
44 return (void*)67890;
47 __attribute__((noinline)) void* operator new(std::size_t size, std::align_val_t al, const std::nothrow_t&) noexcept
49 return (void*)78901;
52 __attribute__((noinline)) void* operator new[](std::size_t size, std::align_val_t al, const std::nothrow_t&) noexcept
54 return (void*)89012;
57 __attribute__((noinline)) void operator delete (void* p)
62 __attribute__((noinline)) void operator delete[] (void* p)
67 __attribute__((noinline)) void operator delete (void* ptr, std::align_val_t al ) noexcept
72 __attribute__((noinline)) void operator delete[] (void* ptr, std::align_val_t al ) noexcept
77 int main(void)
79 s* p1 = new s;
80 s* p2 = new (std::nothrow) s;
81 char* c1 = new char[2000];
82 char* c2 = new (std::nothrow) char[2000];
83 s* pa1 = static_cast<s*>(operator new(sizeof(*pa1), static_cast<std::align_val_t>(256U)));
84 s* pa2 = static_cast<s*>(operator new[](sizeof(*pa2)*10U, static_cast<std::align_val_t>(256U)));
85 std::nothrow_t tag;
86 s* pa3 = static_cast<s*>(operator new(sizeof(*pa3), static_cast<std::align_val_t>(256U), tag));
87 s* pa4 = static_cast<s*>(operator new[](sizeof(*pa4)*10U, static_cast<std::align_val_t>(256U), tag));
88 delete p1;
89 delete p2;
90 delete [] c1;
91 delete [] c2;
92 operator delete(pa1, static_cast<std::align_val_t>(256U));
93 operator delete[](pa2, static_cast<std::align_val_t>(256U));
94 operator delete(pa3, static_cast<std::align_val_t>(256U));
95 operator delete[](pa4, static_cast<std::align_val_t>(256U));
96 return 0;