Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1 | // -*- C++ -*- |
| 2 | //===----------------------------- new ------------------------------------===// |
| 3 | // |
Howard Hinnant | c566dc3 | 2010-05-11 21:36:01 +0000 | [diff] [blame] | 4 | // The LLVM Compiler Infrastructure |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5 | // |
Howard Hinnant | ee11c31 | 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 | c51e102 | 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 | 1bc52cf | 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 | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 28 | }; |
| 29 | |
Eric Fiselier | 162922f | 2016-10-14 06:46:30 +0000 | [diff] [blame] | 30 | class bad_array_length : public bad_alloc // FIXME: Not part of C++ |
Marshall Clow | 3bf7713 | 2013-09-11 01:38:42 +0000 | [diff] [blame] | 31 | { |
| 32 | public: |
| 33 | bad_array_length() noexcept; |
| 34 | }; |
| 35 | |
Eric Fiselier | 162922f | 2016-10-14 06:46:30 +0000 | [diff] [blame] | 36 | class bad_array_new_length : public bad_alloc // C++14 |
Marshall Clow | 3bf7713 | 2013-09-11 01:38:42 +0000 | [diff] [blame] | 37 | { |
| 38 | public: |
| 39 | bad_array_new_length() noexcept; |
| 40 | }; |
| 41 | |
Eric Fiselier | 162922f | 2016-10-14 06:46:30 +0000 | [diff] [blame] | 42 | enum class align_val_t : size_t {}; // C++17 |
Howard Hinnant | c51e102 | 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 | 1bc52cf | 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 | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 48 | |
Marshall Clow | df5a11f | 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 | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 51 | } // std |
| 52 | |
Marshall Clow | be8b84d | 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 | 162922f | 2016-10-14 06:46:30 +0000 | [diff] [blame] | 56 | void* operator new(std::size_t size, std::align_val_t alignment, |
Marshall Clow | be8b84d | 2017-12-04 23:03:42 +0000 | [diff] [blame] | 57 | const std::nothrow_t&) noexcept; // replaceable, C++17, nodiscard in C++2a |
Howard Hinnant | 1bc52cf | 2011-05-26 18:23:59 +0000 | [diff] [blame] | 58 | void operator delete(void* ptr) noexcept; // replaceable |
Larisse Voufo | 574190d | 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 | 162922f | 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 | 1bc52cf | 2011-05-26 18:23:59 +0000 | [diff] [blame] | 63 | void operator delete(void* ptr, const std::nothrow_t&) noexcept; // replaceable |
Eric Fiselier | 162922f | 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 | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 66 | |
Marshall Clow | be8b84d | 2017-12-04 23:03:42 +0000 | [diff] [blame] | 67 | void* operator new[](std::size_t size); // replaceable, nodiscard in C++2a |
Eric Fiselier | 162922f | 2016-10-14 06:46:30 +0000 | [diff] [blame] | 68 | void* operator new[](std::size_t size, |
Marshall Clow | be8b84d | 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 | 162922f | 2016-10-14 06:46:30 +0000 | [diff] [blame] | 71 | void* operator new[](std::size_t size, std::align_val_t alignment, |
Marshall Clow | be8b84d | 2017-12-04 23:03:42 +0000 | [diff] [blame] | 72 | const std::nothrow_t&) noexcept; // replaceable, C++17, nodiscard in C++2a |
Howard Hinnant | 1bc52cf | 2011-05-26 18:23:59 +0000 | [diff] [blame] | 73 | void operator delete[](void* ptr) noexcept; // replaceable |
Larisse Voufo | 574190d | 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 | 162922f | 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 | 1bc52cf | 2011-05-26 18:23:59 +0000 | [diff] [blame] | 79 | void operator delete[](void* ptr, const std::nothrow_t&) noexcept; // replaceable |
Eric Fiselier | 162922f | 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 | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 82 | |
Marshall Clow | be8b84d | 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 | 1bc52cf | 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 | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 87 | |
| 88 | */ |
| 89 | |
| 90 | #include <__config> |
| 91 | #include <exception> |
Eric Fiselier | 06548ab | 2018-03-22 04:42:56 +0000 | [diff] [blame] | 92 | #include <type_traits> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 93 | #include <cstddef> |
Marshall Clow | 0a1e750 | 2018-09-12 19:41:40 +0000 | [diff] [blame] | 94 | #include <version> |
Eric Fiselier | 279c319 | 2016-09-06 21:25:27 +0000 | [diff] [blame] | 95 | #ifdef _LIBCPP_NO_EXCEPTIONS |
| 96 | #include <cstdlib> |
| 97 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 98 | |
Shoaib Meenai | cfd1960 | 2017-10-09 19:25:17 +0000 | [diff] [blame] | 99 | #if defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_NO_VCRUNTIME) |
Eric Fiselier | ec3a167 | 2017-02-10 08:57:35 +0000 | [diff] [blame] | 100 | #include <new.h> |
| 101 | #endif |
| 102 | |
Howard Hinnant | aaaa52b | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 103 | #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 104 | #pragma GCC system_header |
Howard Hinnant | aaaa52b | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 105 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 106 | |
Eric Fiselier | ff4c8a2 | 2018-10-11 00:17:24 +0000 | [diff] [blame^] | 107 | #if !defined(_LIBCPP_BUILDING_LIBRARY) && _LIBCPP_STD_VER < 14 |
| 108 | # define _LIBCPP_HAS_NO_LIBRARY_SIZED_DEALLOCATION |
| 109 | #endif |
| 110 | |
| 111 | #if defined(_LIBCPP_HAS_NO_LIBRARY_SIZED_DEALLOCATION) || \ |
| 112 | !defined(__cpp_sized_deallocation) || __cpp_sized_deallocation < 201309 |
Eric Fiselier | 162922f | 2016-10-14 06:46:30 +0000 | [diff] [blame] | 113 | # define _LIBCPP_HAS_NO_SIZED_DEALLOCATION |
| 114 | #endif |
| 115 | |
Eric Fiselier | 06548ab | 2018-03-22 04:42:56 +0000 | [diff] [blame] | 116 | #if !__has_builtin(__builtin_operator_new) || \ |
Eric Fiselier | ff4c8a2 | 2018-10-11 00:17:24 +0000 | [diff] [blame^] | 117 | __has_builtin(__builtin_operator_new) < 201802L |
| 118 | #define _LIBCPP_HAS_NO_BUILTIN_OVERLOADED_OPERATOR_NEW_DELETE |
Eric Fiselier | 06548ab | 2018-03-22 04:42:56 +0000 | [diff] [blame] | 119 | #endif |
| 120 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 121 | namespace std // purposefully not using versioning namespace |
| 122 | { |
| 123 | |
Shoaib Meenai | cfd1960 | 2017-10-09 19:25:17 +0000 | [diff] [blame] | 124 | #if !defined(_LIBCPP_ABI_MICROSOFT) || defined(_LIBCPP_NO_VCRUNTIME) |
Eric Fiselier | ec3a167 | 2017-02-10 08:57:35 +0000 | [diff] [blame] | 125 | struct _LIBCPP_TYPE_VIS nothrow_t {}; |
| 126 | extern _LIBCPP_FUNC_VIS const nothrow_t nothrow; |
| 127 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 128 | class _LIBCPP_EXCEPTION_ABI bad_alloc |
| 129 | : public exception |
| 130 | { |
| 131 | public: |
Howard Hinnant | 1bc52cf | 2011-05-26 18:23:59 +0000 | [diff] [blame] | 132 | bad_alloc() _NOEXCEPT; |
| 133 | virtual ~bad_alloc() _NOEXCEPT; |
| 134 | virtual const char* what() const _NOEXCEPT; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 135 | }; |
| 136 | |
| 137 | class _LIBCPP_EXCEPTION_ABI bad_array_new_length |
| 138 | : public bad_alloc |
| 139 | { |
| 140 | public: |
Howard Hinnant | 1bc52cf | 2011-05-26 18:23:59 +0000 | [diff] [blame] | 141 | bad_array_new_length() _NOEXCEPT; |
| 142 | virtual ~bad_array_new_length() _NOEXCEPT; |
| 143 | virtual const char* what() const _NOEXCEPT; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 144 | }; |
| 145 | |
Eric Fiselier | ec3a167 | 2017-02-10 08:57:35 +0000 | [diff] [blame] | 146 | typedef void (*new_handler)(); |
| 147 | _LIBCPP_FUNC_VIS new_handler set_new_handler(new_handler) _NOEXCEPT; |
| 148 | _LIBCPP_FUNC_VIS new_handler get_new_handler() _NOEXCEPT; |
| 149 | |
Shoaib Meenai | cfd1960 | 2017-10-09 19:25:17 +0000 | [diff] [blame] | 150 | #endif // !_LIBCPP_ABI_MICROSOFT || _LIBCPP_NO_VCRUNTIME |
Eric Fiselier | ec3a167 | 2017-02-10 08:57:35 +0000 | [diff] [blame] | 151 | |
Marshall Clow | 8fea161 | 2016-08-25 15:09:01 +0000 | [diff] [blame] | 152 | _LIBCPP_NORETURN _LIBCPP_FUNC_VIS void __throw_bad_alloc(); // not in C++ spec |
| 153 | |
Eric Fiselier | ec3a167 | 2017-02-10 08:57:35 +0000 | [diff] [blame] | 154 | #if defined(_LIBCPP_BUILDING_LIBRARY) || (_LIBCPP_STD_VER > 11) |
Howard Hinnant | 4582a2b | 2013-11-07 17:15:51 +0000 | [diff] [blame] | 155 | |
Mehdi Amini | 228053d | 2017-05-04 17:08:54 +0000 | [diff] [blame] | 156 | class _LIBCPP_EXCEPTION_ABI _LIBCPP_AVAILABILITY_BAD_ARRAY_LENGTH |
| 157 | bad_array_length : public bad_alloc { |
Marshall Clow | 3bf7713 | 2013-09-11 01:38:42 +0000 | [diff] [blame] | 158 | public: |
| 159 | bad_array_length() _NOEXCEPT; |
| 160 | virtual ~bad_array_length() _NOEXCEPT; |
| 161 | virtual const char* what() const _NOEXCEPT; |
| 162 | }; |
Howard Hinnant | 4582a2b | 2013-11-07 17:15:51 +0000 | [diff] [blame] | 163 | |
| 164 | #define _LIBCPP_BAD_ARRAY_LENGTH_DEFINED |
| 165 | |
Louis Dionne | 5e0eadd | 2018-08-01 02:08:59 +0000 | [diff] [blame] | 166 | #endif // defined(_LIBCPP_BUILDING_LIBRARY) || (_LIBCPP_STD_VER > 11) |
Marshall Clow | 3bf7713 | 2013-09-11 01:38:42 +0000 | [diff] [blame] | 167 | |
Eric Fiselier | ff4c8a2 | 2018-10-11 00:17:24 +0000 | [diff] [blame^] | 168 | #if !defined(_LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION) && \ |
| 169 | !defined(_LIBCPP_DEFER_NEW_TO_VCRUNTIME) |
Eric Fiselier | 162922f | 2016-10-14 06:46:30 +0000 | [diff] [blame] | 170 | #ifndef _LIBCPP_CXX03_LANG |
| 171 | enum class _LIBCPP_ENUM_VIS align_val_t : size_t { }; |
| 172 | #else |
| 173 | enum align_val_t { __zero = 0, __max = (size_t)-1 }; |
| 174 | #endif |
| 175 | #endif |
| 176 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 177 | } // std |
| 178 | |
Eric Fiselier | 499a0a5 | 2017-01-02 23:27:42 +0000 | [diff] [blame] | 179 | #if defined(_LIBCPP_CXX03_LANG) |
Eric Fiselier | 162922f | 2016-10-14 06:46:30 +0000 | [diff] [blame] | 180 | #define _THROW_BAD_ALLOC throw(std::bad_alloc) |
| 181 | #else |
| 182 | #define _THROW_BAD_ALLOC |
Howard Hinnant | 1bc52cf | 2011-05-26 18:23:59 +0000 | [diff] [blame] | 183 | #endif |
Eric Fiselier | 162922f | 2016-10-14 06:46:30 +0000 | [diff] [blame] | 184 | |
Eric Fiselier | ff4c8a2 | 2018-10-11 00:17:24 +0000 | [diff] [blame^] | 185 | #if !defined(_LIBCPP_DEFER_NEW_TO_VCRUNTIME) |
Eric Fiselier | ec3a167 | 2017-02-10 08:57:35 +0000 | [diff] [blame] | 186 | |
Marshall Clow | be8b84d | 2017-12-04 23:03:42 +0000 | [diff] [blame] | 187 | _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new(std::size_t __sz) _THROW_BAD_ALLOC; |
| 188 | _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new(std::size_t __sz, const std::nothrow_t&) _NOEXCEPT _NOALIAS; |
Shoaib Meenai | 2d71db4 | 2016-11-16 22:18:10 +0000 | [diff] [blame] | 189 | _LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete(void* __p) _NOEXCEPT; |
| 190 | _LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete(void* __p, const std::nothrow_t&) _NOEXCEPT; |
Eric Fiselier | ff4c8a2 | 2018-10-11 00:17:24 +0000 | [diff] [blame^] | 191 | #ifndef _LIBCPP_HAS_NO_LIBRARY_SIZED_DEALLOCATION |
Mehdi Amini | 228053d | 2017-05-04 17:08:54 +0000 | [diff] [blame] | 192 | _LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_AVAILABILITY_SIZED_NEW_DELETE void operator delete(void* __p, std::size_t __sz) _NOEXCEPT; |
Larisse Voufo | a744a7e | 2015-02-20 06:13:05 +0000 | [diff] [blame] | 193 | #endif |
Howard Hinnant | a37d3cf | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 194 | |
Marshall Clow | be8b84d | 2017-12-04 23:03:42 +0000 | [diff] [blame] | 195 | _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new[](std::size_t __sz) _THROW_BAD_ALLOC; |
| 196 | _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new[](std::size_t __sz, const std::nothrow_t&) _NOEXCEPT _NOALIAS; |
Shoaib Meenai | 2d71db4 | 2016-11-16 22:18:10 +0000 | [diff] [blame] | 197 | _LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete[](void* __p) _NOEXCEPT; |
| 198 | _LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete[](void* __p, const std::nothrow_t&) _NOEXCEPT; |
Eric Fiselier | ff4c8a2 | 2018-10-11 00:17:24 +0000 | [diff] [blame^] | 199 | #ifndef _LIBCPP_HAS_NO_LIBRARY_SIZED_DEALLOCATION |
Mehdi Amini | 228053d | 2017-05-04 17:08:54 +0000 | [diff] [blame] | 200 | _LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_AVAILABILITY_SIZED_NEW_DELETE void operator delete[](void* __p, std::size_t __sz) _NOEXCEPT; |
Larisse Voufo | a744a7e | 2015-02-20 06:13:05 +0000 | [diff] [blame] | 201 | #endif |
Howard Hinnant | a37d3cf | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 202 | |
Eric Fiselier | ff4c8a2 | 2018-10-11 00:17:24 +0000 | [diff] [blame^] | 203 | #ifndef _LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION |
Marshall Clow | be8b84d | 2017-12-04 23:03:42 +0000 | [diff] [blame] | 204 | _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new(std::size_t __sz, std::align_val_t) _THROW_BAD_ALLOC; |
| 205 | _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 | 8c77d15 | 2017-06-30 18:50:23 +0000 | [diff] [blame] | 206 | _LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete(void* __p, std::align_val_t) _NOEXCEPT; |
| 207 | _LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete(void* __p, std::align_val_t, const std::nothrow_t&) _NOEXCEPT; |
Eric Fiselier | ff4c8a2 | 2018-10-11 00:17:24 +0000 | [diff] [blame^] | 208 | #ifndef _LIBCPP_HAS_NO_LIBRARY_SIZED_DEALLOCATION |
Akira Hatanaka | 8c77d15 | 2017-06-30 18:50:23 +0000 | [diff] [blame] | 209 | _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 | 162922f | 2016-10-14 06:46:30 +0000 | [diff] [blame] | 210 | #endif |
| 211 | |
Marshall Clow | be8b84d | 2017-12-04 23:03:42 +0000 | [diff] [blame] | 212 | _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new[](std::size_t __sz, std::align_val_t) _THROW_BAD_ALLOC; |
| 213 | _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 | 8c77d15 | 2017-06-30 18:50:23 +0000 | [diff] [blame] | 214 | _LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete[](void* __p, std::align_val_t) _NOEXCEPT; |
| 215 | _LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete[](void* __p, std::align_val_t, const std::nothrow_t&) _NOEXCEPT; |
Eric Fiselier | ff4c8a2 | 2018-10-11 00:17:24 +0000 | [diff] [blame^] | 216 | #ifndef _LIBCPP_HAS_NO_LIBRARY_SIZED_DEALLOCATION |
Akira Hatanaka | 8c77d15 | 2017-06-30 18:50:23 +0000 | [diff] [blame] | 217 | _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 | 162922f | 2016-10-14 06:46:30 +0000 | [diff] [blame] | 218 | #endif |
| 219 | #endif |
| 220 | |
Marshall Clow | be8b84d | 2017-12-04 23:03:42 +0000 | [diff] [blame] | 221 | _LIBCPP_NODISCARD_AFTER_CXX17 inline _LIBCPP_INLINE_VISIBILITY void* operator new (std::size_t, void* __p) _NOEXCEPT {return __p;} |
| 222 | _LIBCPP_NODISCARD_AFTER_CXX17 inline _LIBCPP_INLINE_VISIBILITY void* operator new[](std::size_t, void* __p) _NOEXCEPT {return __p;} |
Howard Hinnant | b8a8ca2 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 223 | inline _LIBCPP_INLINE_VISIBILITY void operator delete (void*, void*) _NOEXCEPT {} |
| 224 | inline _LIBCPP_INLINE_VISIBILITY void operator delete[](void*, void*) _NOEXCEPT {} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 225 | |
Eric Fiselier | ff4c8a2 | 2018-10-11 00:17:24 +0000 | [diff] [blame^] | 226 | #endif // !_LIBCPP_DEFER_NEW_TO_VCRUNTIME |
Eric Fiselier | ec3a167 | 2017-02-10 08:57:35 +0000 | [diff] [blame] | 227 | |
Richard Smith | 1f1c147 | 2014-06-04 19:54:15 +0000 | [diff] [blame] | 228 | _LIBCPP_BEGIN_NAMESPACE_STD |
| 229 | |
Eric Fiselier | 06548ab | 2018-03-22 04:42:56 +0000 | [diff] [blame] | 230 | _LIBCPP_CONSTEXPR inline _LIBCPP_INLINE_VISIBILITY bool __is_overaligned_for_new(size_t __align) _NOEXCEPT { |
| 231 | #ifdef __STDCPP_DEFAULT_NEW_ALIGNMENT__ |
| 232 | return __align > __STDCPP_DEFAULT_NEW_ALIGNMENT__; |
| 233 | #else |
| 234 | return __align > alignment_of<max_align_t>::value; |
| 235 | #endif |
| 236 | } |
| 237 | |
| 238 | inline _LIBCPP_INLINE_VISIBILITY void *__libcpp_allocate(size_t __size, size_t __align) { |
| 239 | #ifndef _LIBCPP_HAS_NO_ALIGNED_ALLOCATION |
| 240 | if (__is_overaligned_for_new(__align)) { |
| 241 | const align_val_t __align_val = static_cast<align_val_t>(__align); |
| 242 | # ifdef _LIBCPP_HAS_NO_BUILTIN_ALIGNED_OPERATOR_NEW_DELETE |
| 243 | return ::operator new(__size, __align_val); |
| 244 | # else |
| 245 | return __builtin_operator_new(__size, __align_val); |
| 246 | # endif |
| 247 | } |
| 248 | #else |
| 249 | ((void)__align); |
| 250 | #endif |
Richard Smith | 1f1c147 | 2014-06-04 19:54:15 +0000 | [diff] [blame] | 251 | #ifdef _LIBCPP_HAS_NO_BUILTIN_OPERATOR_NEW_DELETE |
| 252 | return ::operator new(__size); |
| 253 | #else |
| 254 | return __builtin_operator_new(__size); |
| 255 | #endif |
| 256 | } |
| 257 | |
Eric Fiselier | 06548ab | 2018-03-22 04:42:56 +0000 | [diff] [blame] | 258 | inline _LIBCPP_INLINE_VISIBILITY void __libcpp_deallocate(void* __ptr, size_t __align) { |
| 259 | #ifndef _LIBCPP_HAS_NO_ALIGNED_ALLOCATION |
| 260 | if (__is_overaligned_for_new(__align)) { |
| 261 | const align_val_t __align_val = static_cast<align_val_t>(__align); |
Eric Fiselier | ff4c8a2 | 2018-10-11 00:17:24 +0000 | [diff] [blame^] | 262 | # ifdef _LIBCPP_HAS_NO_BUILTIN_OVERLOADED_OPERATOR_NEW_DELETE |
Eric Fiselier | 06548ab | 2018-03-22 04:42:56 +0000 | [diff] [blame] | 263 | return ::operator delete(__ptr, __align_val); |
| 264 | # else |
| 265 | return __builtin_operator_delete(__ptr, __align_val); |
| 266 | # endif |
| 267 | } |
Richard Smith | 1f1c147 | 2014-06-04 19:54:15 +0000 | [diff] [blame] | 268 | #else |
Eric Fiselier | 06548ab | 2018-03-22 04:42:56 +0000 | [diff] [blame] | 269 | ((void)__align); |
| 270 | #endif |
| 271 | #ifdef _LIBCPP_HAS_NO_BUILTIN_OPERATOR_NEW_DELETE |
| 272 | return ::operator delete(__ptr); |
| 273 | #else |
| 274 | return __builtin_operator_delete(__ptr); |
Richard Smith | 1f1c147 | 2014-06-04 19:54:15 +0000 | [diff] [blame] | 275 | #endif |
| 276 | } |
| 277 | |
Marshall Clow | 8fea161 | 2016-08-25 15:09:01 +0000 | [diff] [blame] | 278 | #ifdef _LIBCPP_BAD_ARRAY_LENGTH_DEFINED |
Louis Dionne | 16fe295 | 2018-07-11 23:14:33 +0000 | [diff] [blame] | 279 | _LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY |
Mehdi Amini | 228053d | 2017-05-04 17:08:54 +0000 | [diff] [blame] | 280 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 281 | _LIBCPP_AVAILABILITY_BAD_ARRAY_LENGTH |
| 282 | #endif |
Marshall Clow | 8fea161 | 2016-08-25 15:09:01 +0000 | [diff] [blame] | 283 | void __throw_bad_array_length() |
| 284 | { |
| 285 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 286 | throw bad_array_length(); |
| 287 | #else |
Louis Dionne | 44bcff9 | 2018-08-03 22:36:53 +0000 | [diff] [blame] | 288 | _VSTD::abort(); |
Marshall Clow | 8fea161 | 2016-08-25 15:09:01 +0000 | [diff] [blame] | 289 | #endif |
| 290 | } |
| 291 | #endif |
| 292 | |
Marshall Clow | df5a11f | 2017-11-22 19:49:03 +0000 | [diff] [blame] | 293 | template <class _Tp> |
Louis Dionne | 44bcff9 | 2018-08-03 22:36:53 +0000 | [diff] [blame] | 294 | _LIBCPP_NODISCARD_AFTER_CXX17 inline |
Marshall Clow | df5a11f | 2017-11-22 19:49:03 +0000 | [diff] [blame] | 295 | _LIBCPP_CONSTEXPR _Tp* __launder(_Tp* __p) _NOEXCEPT |
| 296 | { |
| 297 | static_assert (!(is_function<_Tp>::value), "can't launder functions" ); |
| 298 | static_assert (!(is_same<void, typename remove_cv<_Tp>::type>::value), "can't launder cv-void" ); |
| 299 | #ifdef _LIBCPP_COMPILER_HAS_BUILTIN_LAUNDER |
| 300 | return __builtin_launder(__p); |
| 301 | #else |
| 302 | return __p; |
| 303 | #endif |
| 304 | } |
| 305 | |
| 306 | |
| 307 | #if _LIBCPP_STD_VER > 14 |
| 308 | template <class _Tp> |
| 309 | _LIBCPP_NODISCARD_AFTER_CXX17 inline _LIBCPP_INLINE_VISIBILITY |
| 310 | constexpr _Tp* launder(_Tp* __p) noexcept |
| 311 | { |
Marshall Clow | 6ac349c | 2017-11-23 01:25:03 +0000 | [diff] [blame] | 312 | return _VSTD::__launder(__p); |
Marshall Clow | df5a11f | 2017-11-22 19:49:03 +0000 | [diff] [blame] | 313 | } |
| 314 | #endif |
| 315 | |
Richard Smith | 1f1c147 | 2014-06-04 19:54:15 +0000 | [diff] [blame] | 316 | _LIBCPP_END_NAMESPACE_STD |
| 317 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 318 | #endif // _LIBCPP_NEW |