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 | |
Eric Fiselier | 9acbffa | 2016-10-14 06:46:30 +0000 | [diff] [blame] | 30 | class bad_array_length : public bad_alloc // FIXME: Not part of C++ |
Marshall Clow | 7f9f52e | 2013-09-11 01:38:42 +0000 | [diff] [blame] | 31 | { |
| 32 | public: |
| 33 | bad_array_length() noexcept; |
| 34 | }; |
| 35 | |
Eric Fiselier | 9acbffa | 2016-10-14 06:46:30 +0000 | [diff] [blame] | 36 | class bad_array_new_length : public bad_alloc // C++14 |
Marshall Clow | 7f9f52e | 2013-09-11 01:38:42 +0000 | [diff] [blame] | 37 | { |
| 38 | public: |
| 39 | bad_array_new_length() noexcept; |
| 40 | }; |
| 41 | |
Eric Fiselier | 9acbffa | 2016-10-14 06:46:30 +0000 | [diff] [blame] | 42 | enum class align_val_t : size_t {}; // C++17 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 43 | struct nothrow_t {}; |
| 44 | extern const nothrow_t nothrow; |
| 45 | typedef void (*new_handler)(); |
Howard Hinnant | ed56921 | 2011-05-26 18:23:59 +0000 | [diff] [blame] | 46 | new_handler set_new_handler(new_handler new_p) noexcept; |
| 47 | new_handler get_new_handler() noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 48 | |
Marshall Clow | aa0e236 | 2017-11-22 19:49:03 +0000 | [diff] [blame] | 49 | // 21.6.4, pointer optimization barrier |
| 50 | template <class T> constexpr T* launder(T* p) noexcept; // C++17 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 51 | } // std |
| 52 | |
Marshall Clow | 8f6293b | 2017-12-04 23:03:42 +0000 | [diff] [blame] | 53 | void* operator new(std::size_t size); // replaceable, nodiscard in C++2a |
| 54 | void* operator new(std::size_t size, std::align_val_t alignment); // replaceable, C++17, nodiscard in C++2a |
| 55 | void* operator new(std::size_t size, const std::nothrow_t&) noexcept; // replaceable, nodiscard in C++2a |
Eric Fiselier | 9acbffa | 2016-10-14 06:46:30 +0000 | [diff] [blame] | 56 | void* operator new(std::size_t size, std::align_val_t alignment, |
Marshall Clow | 8f6293b | 2017-12-04 23:03:42 +0000 | [diff] [blame] | 57 | const std::nothrow_t&) noexcept; // replaceable, C++17, nodiscard in C++2a |
Howard Hinnant | ed56921 | 2011-05-26 18:23:59 +0000 | [diff] [blame] | 58 | void operator delete(void* ptr) noexcept; // replaceable |
Larisse Voufo | 19efe01 | 2015-02-15 05:18:55 +0000 | [diff] [blame] | 59 | void operator delete(void* ptr, std::size_t size) noexcept; // replaceable, C++14 |
Eric Fiselier | 9acbffa | 2016-10-14 06:46:30 +0000 | [diff] [blame] | 60 | void operator delete(void* ptr, std::align_val_t alignment) noexcept; // replaceable, C++17 |
| 61 | void operator delete(void* ptr, std::size_t size, |
| 62 | std::align_val_t alignment) noexcept; // replaceable, C++17 |
Howard Hinnant | ed56921 | 2011-05-26 18:23:59 +0000 | [diff] [blame] | 63 | void operator delete(void* ptr, const std::nothrow_t&) noexcept; // replaceable |
Eric Fiselier | 9acbffa | 2016-10-14 06:46:30 +0000 | [diff] [blame] | 64 | void operator delete(void* ptr, std:align_val_t alignment, |
| 65 | const std::nothrow_t&) noexcept; // replaceable, C++17 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 66 | |
Marshall Clow | 8f6293b | 2017-12-04 23:03:42 +0000 | [diff] [blame] | 67 | void* operator new[](std::size_t size); // replaceable, nodiscard in C++2a |
Eric Fiselier | 9acbffa | 2016-10-14 06:46:30 +0000 | [diff] [blame] | 68 | void* operator new[](std::size_t size, |
Marshall Clow | 8f6293b | 2017-12-04 23:03:42 +0000 | [diff] [blame] | 69 | std::align_val_t alignment) noexcept; // replaceable, C++17, nodiscard in C++2a |
| 70 | void* operator new[](std::size_t size, const std::nothrow_t&) noexcept; // replaceable, nodiscard in C++2a |
Eric Fiselier | 9acbffa | 2016-10-14 06:46:30 +0000 | [diff] [blame] | 71 | void* operator new[](std::size_t size, std::align_val_t alignment, |
Marshall Clow | 8f6293b | 2017-12-04 23:03:42 +0000 | [diff] [blame] | 72 | const std::nothrow_t&) noexcept; // replaceable, C++17, nodiscard in C++2a |
Howard Hinnant | ed56921 | 2011-05-26 18:23:59 +0000 | [diff] [blame] | 73 | void operator delete[](void* ptr) noexcept; // replaceable |
Larisse Voufo | 19efe01 | 2015-02-15 05:18:55 +0000 | [diff] [blame] | 74 | void operator delete[](void* ptr, std::size_t size) noexcept; // replaceable, C++14 |
Eric Fiselier | 9acbffa | 2016-10-14 06:46:30 +0000 | [diff] [blame] | 75 | void operator delete[](void* ptr, |
| 76 | std::align_val_t alignment) noexcept; // replaceable, C++17 |
| 77 | void operator delete[](void* ptr, std::size_t size, |
| 78 | std::align_val_t alignment) noexcept; // replaceable, C++17 |
Howard Hinnant | ed56921 | 2011-05-26 18:23:59 +0000 | [diff] [blame] | 79 | void operator delete[](void* ptr, const std::nothrow_t&) noexcept; // replaceable |
Eric Fiselier | 9acbffa | 2016-10-14 06:46:30 +0000 | [diff] [blame] | 80 | void operator delete[](void* ptr, std::align_val_t alignment, |
| 81 | const std::nothrow_t&) noexcept; // replaceable, C++17 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 82 | |
Marshall Clow | 8f6293b | 2017-12-04 23:03:42 +0000 | [diff] [blame] | 83 | void* operator new (std::size_t size, void* ptr) noexcept; // nodiscard in C++2a |
| 84 | void* operator new[](std::size_t size, void* ptr) noexcept; // nodiscard in C++2a |
Howard Hinnant | ed56921 | 2011-05-26 18:23:59 +0000 | [diff] [blame] | 85 | void operator delete (void* ptr, void*) noexcept; |
| 86 | void operator delete[](void* ptr, void*) noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 87 | |
| 88 | */ |
| 89 | |
| 90 | #include <__config> |
| 91 | #include <exception> |
| 92 | #include <cstddef> |
Eric Fiselier | dbf60fa | 2016-09-06 21:25:27 +0000 | [diff] [blame] | 93 | #ifdef _LIBCPP_NO_EXCEPTIONS |
| 94 | #include <cstdlib> |
| 95 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 96 | |
Shoaib Meenai | 18dba06 | 2017-10-09 19:25:17 +0000 | [diff] [blame] | 97 | #if defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_NO_VCRUNTIME) |
Eric Fiselier | 1edf316 | 2017-02-10 08:57:35 +0000 | [diff] [blame] | 98 | #include <new.h> |
| 99 | #endif |
| 100 | |
Howard Hinnant | 08e1747 | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 101 | #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 102 | #pragma GCC system_header |
Howard Hinnant | 08e1747 | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 103 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 104 | |
Eric Fiselier | 9acbffa | 2016-10-14 06:46:30 +0000 | [diff] [blame] | 105 | #if !(defined(_LIBCPP_BUILDING_NEW) || _LIBCPP_STD_VER >= 14 || \ |
| 106 | (defined(__cpp_sized_deallocation) && __cpp_sized_deallocation >= 201309)) |
| 107 | # define _LIBCPP_HAS_NO_SIZED_DEALLOCATION |
| 108 | #endif |
| 109 | |
Eric Fiselier | d54d974 | 2017-01-20 01:47:26 +0000 | [diff] [blame] | 110 | #if !defined(_LIBCPP_HAS_NO_ALIGNED_ALLOCATION) && \ |
| 111 | (!(defined(_LIBCPP_BUILDING_NEW) || _LIBCPP_STD_VER > 14 || \ |
| 112 | (defined(__cpp_aligned_new) && __cpp_aligned_new >= 201606))) |
Eric Fiselier | 9acbffa | 2016-10-14 06:46:30 +0000 | [diff] [blame] | 113 | # define _LIBCPP_HAS_NO_ALIGNED_ALLOCATION |
| 114 | #endif |
| 115 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 116 | namespace std // purposefully not using versioning namespace |
| 117 | { |
| 118 | |
Shoaib Meenai | 18dba06 | 2017-10-09 19:25:17 +0000 | [diff] [blame] | 119 | #if !defined(_LIBCPP_ABI_MICROSOFT) || defined(_LIBCPP_NO_VCRUNTIME) |
Eric Fiselier | 1edf316 | 2017-02-10 08:57:35 +0000 | [diff] [blame] | 120 | struct _LIBCPP_TYPE_VIS nothrow_t {}; |
| 121 | extern _LIBCPP_FUNC_VIS const nothrow_t nothrow; |
| 122 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 123 | class _LIBCPP_EXCEPTION_ABI bad_alloc |
| 124 | : public exception |
| 125 | { |
| 126 | public: |
Howard Hinnant | ed56921 | 2011-05-26 18:23:59 +0000 | [diff] [blame] | 127 | bad_alloc() _NOEXCEPT; |
| 128 | virtual ~bad_alloc() _NOEXCEPT; |
| 129 | virtual const char* what() const _NOEXCEPT; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 130 | }; |
| 131 | |
| 132 | class _LIBCPP_EXCEPTION_ABI bad_array_new_length |
| 133 | : public bad_alloc |
| 134 | { |
| 135 | public: |
Howard Hinnant | ed56921 | 2011-05-26 18:23:59 +0000 | [diff] [blame] | 136 | bad_array_new_length() _NOEXCEPT; |
| 137 | virtual ~bad_array_new_length() _NOEXCEPT; |
| 138 | virtual const char* what() const _NOEXCEPT; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 139 | }; |
| 140 | |
Eric Fiselier | 1edf316 | 2017-02-10 08:57:35 +0000 | [diff] [blame] | 141 | typedef void (*new_handler)(); |
| 142 | _LIBCPP_FUNC_VIS new_handler set_new_handler(new_handler) _NOEXCEPT; |
| 143 | _LIBCPP_FUNC_VIS new_handler get_new_handler() _NOEXCEPT; |
| 144 | |
Shoaib Meenai | 18dba06 | 2017-10-09 19:25:17 +0000 | [diff] [blame] | 145 | #endif // !_LIBCPP_ABI_MICROSOFT || _LIBCPP_NO_VCRUNTIME |
Eric Fiselier | 1edf316 | 2017-02-10 08:57:35 +0000 | [diff] [blame] | 146 | |
Marshall Clow | 14c09a2 | 2016-08-25 15:09:01 +0000 | [diff] [blame] | 147 | _LIBCPP_NORETURN _LIBCPP_FUNC_VIS void __throw_bad_alloc(); // not in C++ spec |
| 148 | |
Eric Fiselier | 1edf316 | 2017-02-10 08:57:35 +0000 | [diff] [blame] | 149 | #if defined(_LIBCPP_BUILDING_LIBRARY) || (_LIBCPP_STD_VER > 11) |
Howard Hinnant | 29250b7 | 2013-11-07 17:15:51 +0000 | [diff] [blame] | 150 | |
Mehdi Amini | 907c119 | 2017-05-04 17:08:54 +0000 | [diff] [blame] | 151 | class _LIBCPP_EXCEPTION_ABI _LIBCPP_AVAILABILITY_BAD_ARRAY_LENGTH |
| 152 | bad_array_length : public bad_alloc { |
Marshall Clow | 7f9f52e | 2013-09-11 01:38:42 +0000 | [diff] [blame] | 153 | public: |
| 154 | bad_array_length() _NOEXCEPT; |
| 155 | virtual ~bad_array_length() _NOEXCEPT; |
| 156 | virtual const char* what() const _NOEXCEPT; |
| 157 | }; |
Howard Hinnant | 29250b7 | 2013-11-07 17:15:51 +0000 | [diff] [blame] | 158 | |
| 159 | #define _LIBCPP_BAD_ARRAY_LENGTH_DEFINED |
| 160 | |
| 161 | #endif // defined(_LIBCPP_BUILDING_NEW) || (_LIBCPP_STD_VER > 11) |
Marshall Clow | 7f9f52e | 2013-09-11 01:38:42 +0000 | [diff] [blame] | 162 | |
Eric Fiselier | 22a291c | 2018-02-11 22:00:19 +0000 | [diff] [blame^] | 163 | #if !defined(_LIBCPP_ABI_MICROSOFT) || defined(_LIBCPP_NO_VCRUNTIME) |
Eric Fiselier | 85e34e4 | 2017-01-21 14:42:44 +0000 | [diff] [blame] | 164 | #if !defined(_LIBCPP_HAS_NO_ALIGNED_ALLOCATION) || _LIBCPP_STD_VER > 14 |
Eric Fiselier | 9acbffa | 2016-10-14 06:46:30 +0000 | [diff] [blame] | 165 | #ifndef _LIBCPP_CXX03_LANG |
| 166 | enum class _LIBCPP_ENUM_VIS align_val_t : size_t { }; |
| 167 | #else |
| 168 | enum align_val_t { __zero = 0, __max = (size_t)-1 }; |
| 169 | #endif |
| 170 | #endif |
Eric Fiselier | 22a291c | 2018-02-11 22:00:19 +0000 | [diff] [blame^] | 171 | #endif |
Eric Fiselier | 9acbffa | 2016-10-14 06:46:30 +0000 | [diff] [blame] | 172 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 173 | } // std |
| 174 | |
Eric Fiselier | b45121d | 2017-01-02 23:27:42 +0000 | [diff] [blame] | 175 | #if defined(_LIBCPP_CXX03_LANG) |
Eric Fiselier | 9acbffa | 2016-10-14 06:46:30 +0000 | [diff] [blame] | 176 | #define _THROW_BAD_ALLOC throw(std::bad_alloc) |
| 177 | #else |
| 178 | #define _THROW_BAD_ALLOC |
Howard Hinnant | ed56921 | 2011-05-26 18:23:59 +0000 | [diff] [blame] | 179 | #endif |
Eric Fiselier | 9acbffa | 2016-10-14 06:46:30 +0000 | [diff] [blame] | 180 | |
Shoaib Meenai | 18dba06 | 2017-10-09 19:25:17 +0000 | [diff] [blame] | 181 | #if !defined(_LIBCPP_ABI_MICROSOFT) || defined(_LIBCPP_NO_VCRUNTIME) |
Eric Fiselier | 1edf316 | 2017-02-10 08:57:35 +0000 | [diff] [blame] | 182 | |
Marshall Clow | 8f6293b | 2017-12-04 23:03:42 +0000 | [diff] [blame] | 183 | _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new(std::size_t __sz) _THROW_BAD_ALLOC; |
| 184 | _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new(std::size_t __sz, const std::nothrow_t&) _NOEXCEPT _NOALIAS; |
Shoaib Meenai | e6479bc | 2016-11-16 22:18:10 +0000 | [diff] [blame] | 185 | _LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete(void* __p) _NOEXCEPT; |
| 186 | _LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete(void* __p, const std::nothrow_t&) _NOEXCEPT; |
Eric Fiselier | 9acbffa | 2016-10-14 06:46:30 +0000 | [diff] [blame] | 187 | #ifndef _LIBCPP_HAS_NO_SIZED_DEALLOCATION |
Mehdi Amini | 907c119 | 2017-05-04 17:08:54 +0000 | [diff] [blame] | 188 | _LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_AVAILABILITY_SIZED_NEW_DELETE void operator delete(void* __p, std::size_t __sz) _NOEXCEPT; |
Larisse Voufo | 74f95a0 | 2015-02-20 06:13:05 +0000 | [diff] [blame] | 189 | #endif |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 190 | |
Marshall Clow | 8f6293b | 2017-12-04 23:03:42 +0000 | [diff] [blame] | 191 | _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new[](std::size_t __sz) _THROW_BAD_ALLOC; |
| 192 | _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new[](std::size_t __sz, const std::nothrow_t&) _NOEXCEPT _NOALIAS; |
Shoaib Meenai | e6479bc | 2016-11-16 22:18:10 +0000 | [diff] [blame] | 193 | _LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete[](void* __p) _NOEXCEPT; |
| 194 | _LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete[](void* __p, const std::nothrow_t&) _NOEXCEPT; |
Shoaib Meenai | f66194b | 2016-11-18 04:31:09 +0000 | [diff] [blame] | 195 | #ifndef _LIBCPP_HAS_NO_SIZED_DEALLOCATION |
Mehdi Amini | 907c119 | 2017-05-04 17:08:54 +0000 | [diff] [blame] | 196 | _LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_AVAILABILITY_SIZED_NEW_DELETE void operator delete[](void* __p, std::size_t __sz) _NOEXCEPT; |
Larisse Voufo | 74f95a0 | 2015-02-20 06:13:05 +0000 | [diff] [blame] | 197 | #endif |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 198 | |
Eric Fiselier | 9acbffa | 2016-10-14 06:46:30 +0000 | [diff] [blame] | 199 | #ifndef _LIBCPP_HAS_NO_ALIGNED_ALLOCATION |
Marshall Clow | 8f6293b | 2017-12-04 23:03:42 +0000 | [diff] [blame] | 200 | _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new(std::size_t __sz, std::align_val_t) _THROW_BAD_ALLOC; |
| 201 | _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new(std::size_t __sz, std::align_val_t, const std::nothrow_t&) _NOEXCEPT _NOALIAS; |
Akira Hatanaka | c5247b4 | 2017-06-30 18:50:23 +0000 | [diff] [blame] | 202 | _LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete(void* __p, std::align_val_t) _NOEXCEPT; |
| 203 | _LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete(void* __p, std::align_val_t, const std::nothrow_t&) _NOEXCEPT; |
Eric Fiselier | 9acbffa | 2016-10-14 06:46:30 +0000 | [diff] [blame] | 204 | #ifndef _LIBCPP_HAS_NO_SIZED_DEALLOCATION |
Akira Hatanaka | c5247b4 | 2017-06-30 18:50:23 +0000 | [diff] [blame] | 205 | _LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_AVAILABILITY_SIZED_NEW_DELETE void operator delete(void* __p, std::size_t __sz, std::align_val_t) _NOEXCEPT; |
Eric Fiselier | 9acbffa | 2016-10-14 06:46:30 +0000 | [diff] [blame] | 206 | #endif |
| 207 | |
Marshall Clow | 8f6293b | 2017-12-04 23:03:42 +0000 | [diff] [blame] | 208 | _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new[](std::size_t __sz, std::align_val_t) _THROW_BAD_ALLOC; |
| 209 | _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new[](std::size_t __sz, std::align_val_t, const std::nothrow_t&) _NOEXCEPT _NOALIAS; |
Akira Hatanaka | c5247b4 | 2017-06-30 18:50:23 +0000 | [diff] [blame] | 210 | _LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete[](void* __p, std::align_val_t) _NOEXCEPT; |
| 211 | _LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete[](void* __p, std::align_val_t, const std::nothrow_t&) _NOEXCEPT; |
Eric Fiselier | 9acbffa | 2016-10-14 06:46:30 +0000 | [diff] [blame] | 212 | #ifndef _LIBCPP_HAS_NO_SIZED_DEALLOCATION |
Akira Hatanaka | c5247b4 | 2017-06-30 18:50:23 +0000 | [diff] [blame] | 213 | _LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_AVAILABILITY_SIZED_NEW_DELETE void operator delete[](void* __p, std::size_t __sz, std::align_val_t) _NOEXCEPT; |
Eric Fiselier | 9acbffa | 2016-10-14 06:46:30 +0000 | [diff] [blame] | 214 | #endif |
| 215 | #endif |
| 216 | |
Marshall Clow | 8f6293b | 2017-12-04 23:03:42 +0000 | [diff] [blame] | 217 | _LIBCPP_NODISCARD_AFTER_CXX17 inline _LIBCPP_INLINE_VISIBILITY void* operator new (std::size_t, void* __p) _NOEXCEPT {return __p;} |
| 218 | _LIBCPP_NODISCARD_AFTER_CXX17 inline _LIBCPP_INLINE_VISIBILITY void* operator new[](std::size_t, void* __p) _NOEXCEPT {return __p;} |
Howard Hinnant | 1e56424 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 219 | inline _LIBCPP_INLINE_VISIBILITY void operator delete (void*, void*) _NOEXCEPT {} |
| 220 | inline _LIBCPP_INLINE_VISIBILITY void operator delete[](void*, void*) _NOEXCEPT {} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 221 | |
Shoaib Meenai | 18dba06 | 2017-10-09 19:25:17 +0000 | [diff] [blame] | 222 | #endif // !_LIBCPP_ABI_MICROSOFT || _LIBCPP_NO_VCRUNTIME |
Eric Fiselier | 1edf316 | 2017-02-10 08:57:35 +0000 | [diff] [blame] | 223 | |
Richard Smith | 73c1fce | 2014-06-04 19:54:15 +0000 | [diff] [blame] | 224 | _LIBCPP_BEGIN_NAMESPACE_STD |
| 225 | |
| 226 | inline _LIBCPP_INLINE_VISIBILITY void *__allocate(size_t __size) { |
| 227 | #ifdef _LIBCPP_HAS_NO_BUILTIN_OPERATOR_NEW_DELETE |
| 228 | return ::operator new(__size); |
| 229 | #else |
| 230 | return __builtin_operator_new(__size); |
| 231 | #endif |
| 232 | } |
| 233 | |
Eric Fiselier | 32b19c3 | 2017-01-07 03:01:24 +0000 | [diff] [blame] | 234 | inline _LIBCPP_INLINE_VISIBILITY void __libcpp_deallocate(void *__ptr) { |
Richard Smith | 73c1fce | 2014-06-04 19:54:15 +0000 | [diff] [blame] | 235 | #ifdef _LIBCPP_HAS_NO_BUILTIN_OPERATOR_NEW_DELETE |
| 236 | ::operator delete(__ptr); |
| 237 | #else |
| 238 | __builtin_operator_delete(__ptr); |
| 239 | #endif |
| 240 | } |
| 241 | |
Marshall Clow | 14c09a2 | 2016-08-25 15:09:01 +0000 | [diff] [blame] | 242 | #ifdef _LIBCPP_BAD_ARRAY_LENGTH_DEFINED |
| 243 | _LIBCPP_NORETURN inline _LIBCPP_ALWAYS_INLINE |
Mehdi Amini | 907c119 | 2017-05-04 17:08:54 +0000 | [diff] [blame] | 244 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 245 | _LIBCPP_AVAILABILITY_BAD_ARRAY_LENGTH |
| 246 | #endif |
Marshall Clow | 14c09a2 | 2016-08-25 15:09:01 +0000 | [diff] [blame] | 247 | void __throw_bad_array_length() |
| 248 | { |
| 249 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 250 | throw bad_array_length(); |
| 251 | #else |
| 252 | _VSTD::abort(); |
| 253 | #endif |
| 254 | } |
| 255 | #endif |
| 256 | |
Marshall Clow | aa0e236 | 2017-11-22 19:49:03 +0000 | [diff] [blame] | 257 | template <class _Tp> |
| 258 | _LIBCPP_NODISCARD_AFTER_CXX17 inline |
| 259 | _LIBCPP_CONSTEXPR _Tp* __launder(_Tp* __p) _NOEXCEPT |
| 260 | { |
| 261 | static_assert (!(is_function<_Tp>::value), "can't launder functions" ); |
| 262 | static_assert (!(is_same<void, typename remove_cv<_Tp>::type>::value), "can't launder cv-void" ); |
| 263 | #ifdef _LIBCPP_COMPILER_HAS_BUILTIN_LAUNDER |
| 264 | return __builtin_launder(__p); |
| 265 | #else |
| 266 | return __p; |
| 267 | #endif |
| 268 | } |
| 269 | |
| 270 | |
| 271 | #if _LIBCPP_STD_VER > 14 |
| 272 | template <class _Tp> |
| 273 | _LIBCPP_NODISCARD_AFTER_CXX17 inline _LIBCPP_INLINE_VISIBILITY |
| 274 | constexpr _Tp* launder(_Tp* __p) noexcept |
| 275 | { |
Marshall Clow | 70c7bbd | 2017-11-23 01:25:03 +0000 | [diff] [blame] | 276 | return _VSTD::__launder(__p); |
Marshall Clow | aa0e236 | 2017-11-22 19:49:03 +0000 | [diff] [blame] | 277 | } |
| 278 | #endif |
| 279 | |
Richard Smith | 73c1fce | 2014-06-04 19:54:15 +0000 | [diff] [blame] | 280 | _LIBCPP_END_NAMESPACE_STD |
| 281 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 282 | #endif // _LIBCPP_NEW |