| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1 | // -*- C++ -*- | 
|  | 2 | //===----------------------------- new ------------------------------------===// | 
|  | 3 | // | 
| Howard Hinnant | f5256e1 | 2010-05-11 21:36:01 +0000 | [diff] [blame] | 4 | //                     The LLVM Compiler Infrastructure | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5 | // | 
| Howard Hinnant | b64f8b0 | 2010-11-16 22:09:02 +0000 | [diff] [blame] | 6 | // This file is dual licensed under the MIT and the University of Illinois Open | 
|  | 7 | // Source Licenses. See LICENSE.TXT for details. | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 8 | // | 
|  | 9 | //===----------------------------------------------------------------------===// | 
|  | 10 |  | 
|  | 11 | #ifndef _LIBCPP_NEW | 
|  | 12 | #define _LIBCPP_NEW | 
|  | 13 |  | 
|  | 14 | /* | 
|  | 15 | new synopsis | 
|  | 16 |  | 
|  | 17 | namespace std | 
|  | 18 | { | 
|  | 19 |  | 
|  | 20 | class bad_alloc | 
|  | 21 | : public exception | 
|  | 22 | { | 
|  | 23 | public: | 
| Howard Hinnant | ed56921 | 2011-05-26 18:23:59 +0000 | [diff] [blame] | 24 | bad_alloc() noexcept; | 
|  | 25 | bad_alloc(const bad_alloc&) noexcept; | 
|  | 26 | bad_alloc& operator=(const bad_alloc&) noexcept; | 
|  | 27 | virtual const char* what() const noexcept; | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 28 | }; | 
|  | 29 |  | 
|  | 30 | struct nothrow_t {}; | 
|  | 31 | extern const nothrow_t nothrow; | 
|  | 32 | typedef void (*new_handler)(); | 
| Howard Hinnant | ed56921 | 2011-05-26 18:23:59 +0000 | [diff] [blame] | 33 | new_handler set_new_handler(new_handler new_p) noexcept; | 
|  | 34 | new_handler get_new_handler() noexcept; | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 35 |  | 
|  | 36 | }  // std | 
|  | 37 |  | 
| Howard Hinnant | ed56921 | 2011-05-26 18:23:59 +0000 | [diff] [blame] | 38 | void* operator new(std::size_t size);                                   // replaceable | 
|  | 39 | void* operator new(std::size_t size, const std::nothrow_t&) noexcept;   // replaceable | 
|  | 40 | void  operator delete(void* ptr) noexcept;                              // replaceable | 
|  | 41 | void  operator delete(void* ptr, const std::nothrow_t&) noexcept;       // replaceable | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 42 |  | 
| Howard Hinnant | ed56921 | 2011-05-26 18:23:59 +0000 | [diff] [blame] | 43 | void* operator new[](std::size_t size);                                 // replaceable | 
|  | 44 | void* operator new[](std::size_t size, const std::nothrow_t&) noexcept; // replaceable | 
|  | 45 | void  operator delete[](void* ptr) noexcept;                            // replaceable | 
|  | 46 | void  operator delete[](void* ptr, const std::nothrow_t&) noexcept;     // replaceable | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 47 |  | 
| Howard Hinnant | ed56921 | 2011-05-26 18:23:59 +0000 | [diff] [blame] | 48 | void* operator new  (std::size_t size, void* ptr) noexcept; | 
|  | 49 | void* operator new[](std::size_t size, void* ptr) noexcept; | 
|  | 50 | void  operator delete  (void* ptr, void*) noexcept; | 
|  | 51 | void  operator delete[](void* ptr, void*) noexcept; | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 52 |  | 
|  | 53 | */ | 
|  | 54 |  | 
|  | 55 | #include <__config> | 
|  | 56 | #include <exception> | 
|  | 57 | #include <cstddef> | 
|  | 58 |  | 
| Howard Hinnant | 08e1747 | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 59 | #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 60 | #pragma GCC system_header | 
| Howard Hinnant | 08e1747 | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 61 | #endif | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 62 |  | 
|  | 63 | namespace std  // purposefully not using versioning namespace | 
|  | 64 | { | 
|  | 65 |  | 
|  | 66 | class _LIBCPP_EXCEPTION_ABI bad_alloc | 
|  | 67 | : public exception | 
|  | 68 | { | 
|  | 69 | public: | 
| Howard Hinnant | ed56921 | 2011-05-26 18:23:59 +0000 | [diff] [blame] | 70 | bad_alloc() _NOEXCEPT; | 
|  | 71 | virtual ~bad_alloc() _NOEXCEPT; | 
|  | 72 | virtual const char* what() const _NOEXCEPT; | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 73 | }; | 
|  | 74 |  | 
|  | 75 | class _LIBCPP_EXCEPTION_ABI bad_array_new_length | 
|  | 76 | : public bad_alloc | 
|  | 77 | { | 
|  | 78 | public: | 
| Howard Hinnant | ed56921 | 2011-05-26 18:23:59 +0000 | [diff] [blame] | 79 | bad_array_new_length() _NOEXCEPT; | 
|  | 80 | virtual ~bad_array_new_length() _NOEXCEPT; | 
|  | 81 | virtual const char* what() const _NOEXCEPT; | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 82 | }; | 
|  | 83 |  | 
| Nick Kledzik | 804b6e7 | 2010-05-14 20:19:37 +0000 | [diff] [blame] | 84 | void __throw_bad_alloc();  // not in C++ spec | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 85 |  | 
| Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 86 | struct _LIBCPP_VISIBLE nothrow_t {}; | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 87 | extern _LIBCPP_VISIBLE const nothrow_t nothrow; | 
|  | 88 | typedef void (*new_handler)(); | 
| Howard Hinnant | ed56921 | 2011-05-26 18:23:59 +0000 | [diff] [blame] | 89 | _LIBCPP_VISIBLE new_handler set_new_handler(new_handler) _NOEXCEPT; | 
|  | 90 | _LIBCPP_VISIBLE new_handler get_new_handler() _NOEXCEPT; | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 91 |  | 
|  | 92 | }  // std | 
|  | 93 |  | 
| Howard Hinnant | 2b1b2d4 | 2011-06-14 19:58:17 +0000 | [diff] [blame] | 94 | _LIBCPP_VISIBLE void* operator new(std::size_t __sz) | 
| Howard Hinnant | ed56921 | 2011-05-26 18:23:59 +0000 | [diff] [blame] | 95 | #if !__has_feature(cxx_noexcept) | 
|  | 96 | throw(std::bad_alloc) | 
|  | 97 | #endif | 
|  | 98 | ; | 
| Nuno Lopes | 518d150 | 2012-06-28 16:47:34 +0000 | [diff] [blame] | 99 | _LIBCPP_VISIBLE void* operator new(std::size_t __sz, const std::nothrow_t&) _NOEXCEPT _NOALIAS; | 
| Howard Hinnant | 2b1b2d4 | 2011-06-14 19:58:17 +0000 | [diff] [blame] | 100 | _LIBCPP_VISIBLE void  operator delete(void* __p) _NOEXCEPT; | 
|  | 101 | _LIBCPP_VISIBLE void  operator delete(void* __p, const std::nothrow_t&) _NOEXCEPT; | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 102 |  | 
| Howard Hinnant | 2b1b2d4 | 2011-06-14 19:58:17 +0000 | [diff] [blame] | 103 | _LIBCPP_VISIBLE void* operator new[](std::size_t __sz) | 
| Howard Hinnant | ed56921 | 2011-05-26 18:23:59 +0000 | [diff] [blame] | 104 | #if !__has_feature(cxx_noexcept) | 
|  | 105 | throw(std::bad_alloc) | 
|  | 106 | #endif | 
|  | 107 | ; | 
| Nuno Lopes | 518d150 | 2012-06-28 16:47:34 +0000 | [diff] [blame] | 108 | _LIBCPP_VISIBLE void* operator new[](std::size_t __sz, const std::nothrow_t&) _NOEXCEPT _NOALIAS; | 
| Howard Hinnant | 2b1b2d4 | 2011-06-14 19:58:17 +0000 | [diff] [blame] | 109 | _LIBCPP_VISIBLE void  operator delete[](void* __p) _NOEXCEPT; | 
|  | 110 | _LIBCPP_VISIBLE void  operator delete[](void* __p, const std::nothrow_t&) _NOEXCEPT; | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 111 |  | 
| Howard Hinnant | ed56921 | 2011-05-26 18:23:59 +0000 | [diff] [blame] | 112 | _LIBCPP_INLINE_VISIBILITY inline void* operator new  (std::size_t, void* __p) _NOEXCEPT {return __p;} | 
|  | 113 | _LIBCPP_INLINE_VISIBILITY inline void* operator new[](std::size_t, void* __p) _NOEXCEPT {return __p;} | 
|  | 114 | _LIBCPP_INLINE_VISIBILITY inline void  operator delete  (void*, void*) _NOEXCEPT {} | 
|  | 115 | _LIBCPP_INLINE_VISIBILITY inline void  operator delete[](void*, void*) _NOEXCEPT {} | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 116 |  | 
|  | 117 | #endif  // _LIBCPP_NEW |