2 //===----------------------------- new ------------------------------------===//
4 // The LLVM Compiler Infrastructure
6 // This file is dual licensed under the MIT and the University of Illinois Open
7 // Source Licenses. See LICENSE.TXT for details.
9 //===----------------------------------------------------------------------===//
25 bad_alloc(const bad_alloc&) noexcept;
26 bad_alloc& operator=(const bad_alloc&) noexcept;
27 virtual const char* what() const noexcept;
30 class bad_array_length : public bad_alloc // FIXME: Not part of C++
33 bad_array_length() noexcept;
36 class bad_array_new_length : public bad_alloc // C++14
39 bad_array_new_length() noexcept;
42 enum class align_val_t : size_t {}; // C++17
44 extern const nothrow_t nothrow;
45 typedef void (*new_handler)();
46 new_handler set_new_handler(new_handler new_p) noexcept;
47 new_handler get_new_handler() noexcept;
51 void* operator new(std::size_t size); // replaceable
52 void* operator new(std::size_t size, std::align_val_t alignment); // replaceable, C++17
53 void* operator new(std::size_t size, const std::nothrow_t&) noexcept; // replaceable
54 void* operator new(std::size_t size, std::align_val_t alignment,
55 const std::nothrow_t&) noexcept; // replaceable, C++17
56 void operator delete(void* ptr) noexcept; // replaceable
57 void operator delete(void* ptr, std::size_t size) noexcept; // replaceable, C++14
58 void operator delete(void* ptr, std::align_val_t alignment) noexcept; // replaceable, C++17
59 void operator delete(void* ptr, std::size_t size,
60 std::align_val_t alignment) noexcept; // replaceable, C++17
61 void operator delete(void* ptr, const std::nothrow_t&) noexcept; // replaceable
62 void operator delete(void* ptr, std:align_val_t alignment,
63 const std::nothrow_t&) noexcept; // replaceable, C++17
65 void* operator new[](std::size_t size); // replaceable
66 void* operator new[](std::size_t size,
67 std::align_val_t alignment) noexcept; // replaceable, C++17
68 void* operator new[](std::size_t size, const std::nothrow_t&) noexcept; // replaceable
69 void* operator new[](std::size_t size, std::align_val_t alignment,
70 const std::nothrow_t&) noexcept; // replaceable, C++17
71 void operator delete[](void* ptr) noexcept; // replaceable
72 void operator delete[](void* ptr, std::size_t size) noexcept; // replaceable, C++14
73 void operator delete[](void* ptr,
74 std::align_val_t alignment) noexcept; // replaceable, C++17
75 void operator delete[](void* ptr, std::size_t size,
76 std::align_val_t alignment) noexcept; // replaceable, C++17
77 void operator delete[](void* ptr, const std::nothrow_t&) noexcept; // replaceable
78 void operator delete[](void* ptr, std::align_val_t alignment,
79 const std::nothrow_t&) noexcept; // replaceable, C++17
81 void* operator new (std::size_t size, void* ptr) noexcept;
82 void* operator new[](std::size_t size, void* ptr) noexcept;
83 void operator delete (void* ptr, void*) noexcept;
84 void operator delete[](void* ptr, void*) noexcept;
91 #ifdef _LIBCPP_NO_EXCEPTIONS
95 #include <__undef___deallocate>
97 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
98 #pragma GCC system_header
101 #if !(defined(_LIBCPP_BUILDING_NEW) || _LIBCPP_STD_VER >= 14 || \
102 (defined(__cpp_sized_deallocation) && __cpp_sized_deallocation >= 201309))
103 # define _LIBCPP_HAS_NO_SIZED_DEALLOCATION
106 #if !(defined(_LIBCPP_BUILDING_NEW) || _LIBCPP_STD_VER > 14 || \
107 (defined(__cpp_aligned_new) && __cpp_aligned_new >= 201606))
108 # define _LIBCPP_HAS_NO_ALIGNED_ALLOCATION
111 namespace std // purposefully not using versioning namespace
114 class _LIBCPP_EXCEPTION_ABI bad_alloc
118 bad_alloc() _NOEXCEPT;
119 virtual ~bad_alloc() _NOEXCEPT;
120 virtual const char* what() const _NOEXCEPT;
123 class _LIBCPP_EXCEPTION_ABI bad_array_new_length
127 bad_array_new_length() _NOEXCEPT;
128 virtual ~bad_array_new_length() _NOEXCEPT;
129 virtual const char* what() const _NOEXCEPT;
132 _LIBCPP_NORETURN _LIBCPP_FUNC_VIS void __throw_bad_alloc(); // not in C++ spec
134 #if defined(_LIBCPP_BUILDING_NEW) || (_LIBCPP_STD_VER > 11)
136 class _LIBCPP_EXCEPTION_ABI bad_array_length
140 bad_array_length() _NOEXCEPT;
141 virtual ~bad_array_length() _NOEXCEPT;
142 virtual const char* what() const _NOEXCEPT;
145 #define _LIBCPP_BAD_ARRAY_LENGTH_DEFINED
147 #endif // defined(_LIBCPP_BUILDING_NEW) || (_LIBCPP_STD_VER > 11)
149 #ifndef _LIBCPP_HAS_NO_ALIGNED_ALLOCATION
150 #ifndef _LIBCPP_CXX03_LANG
151 enum class _LIBCPP_ENUM_VIS align_val_t : size_t { };
153 enum align_val_t { __zero = 0, __max = (size_t)-1 };
157 struct _LIBCPP_TYPE_VIS nothrow_t {};
158 extern _LIBCPP_FUNC_VIS const nothrow_t nothrow;
159 typedef void (*new_handler)();
160 _LIBCPP_FUNC_VIS new_handler set_new_handler(new_handler) _NOEXCEPT;
161 _LIBCPP_FUNC_VIS new_handler get_new_handler() _NOEXCEPT;
165 #if defined(_LIBCPP_CXX03_LANG)
166 #define _THROW_BAD_ALLOC throw(std::bad_alloc)
168 #define _THROW_BAD_ALLOC
171 _LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new(std::size_t __sz) _THROW_BAD_ALLOC;
172 _LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new(std::size_t __sz, const std::nothrow_t&) _NOEXCEPT _NOALIAS;
173 _LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete(void* __p) _NOEXCEPT;
174 _LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete(void* __p, const std::nothrow_t&) _NOEXCEPT;
175 #ifndef _LIBCPP_HAS_NO_SIZED_DEALLOCATION
176 _LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete(void* __p, std::size_t __sz) _NOEXCEPT;
179 _LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new[](std::size_t __sz) _THROW_BAD_ALLOC;
180 _LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new[](std::size_t __sz, const std::nothrow_t&) _NOEXCEPT _NOALIAS;
181 _LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete[](void* __p) _NOEXCEPT;
182 _LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete[](void* __p, const std::nothrow_t&) _NOEXCEPT;
183 #ifndef _LIBCPP_HAS_NO_SIZED_DEALLOCATION
184 _LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete[](void* __p, std::size_t __sz) _NOEXCEPT;
187 #ifndef _LIBCPP_HAS_NO_ALIGNED_ALLOCATION
188 _LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new(std::size_t __sz, std::align_val_t) _THROW_BAD_ALLOC;
189 _LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new(std::size_t __sz, std::align_val_t, const std::nothrow_t&) _NOEXCEPT _NOALIAS;
190 _LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete(void* __p, std::align_val_t) _NOEXCEPT;
191 _LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete(void* __p, std::align_val_t, const std::nothrow_t&) _NOEXCEPT;
192 #ifndef _LIBCPP_HAS_NO_SIZED_DEALLOCATION
193 _LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete(void* __p, std::size_t __sz, std::align_val_t) _NOEXCEPT;
196 _LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new[](std::size_t __sz, std::align_val_t) _THROW_BAD_ALLOC;
197 _LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new[](std::size_t __sz, std::align_val_t, const std::nothrow_t&) _NOEXCEPT _NOALIAS;
198 _LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete[](void* __p, std::align_val_t) _NOEXCEPT;
199 _LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete[](void* __p, std::align_val_t, const std::nothrow_t&) _NOEXCEPT;
200 #ifndef _LIBCPP_HAS_NO_SIZED_DEALLOCATION
201 _LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete[](void* __p, std::size_t __sz, std::align_val_t) _NOEXCEPT;
205 inline _LIBCPP_INLINE_VISIBILITY void* operator new (std::size_t, void* __p) _NOEXCEPT {return __p;}
206 inline _LIBCPP_INLINE_VISIBILITY void* operator new[](std::size_t, void* __p) _NOEXCEPT {return __p;}
207 inline _LIBCPP_INLINE_VISIBILITY void operator delete (void*, void*) _NOEXCEPT {}
208 inline _LIBCPP_INLINE_VISIBILITY void operator delete[](void*, void*) _NOEXCEPT {}
210 _LIBCPP_BEGIN_NAMESPACE_STD
212 inline _LIBCPP_INLINE_VISIBILITY void *__allocate(size_t __size) {
213 #ifdef _LIBCPP_HAS_NO_BUILTIN_OPERATOR_NEW_DELETE
214 return ::operator new(__size);
216 return __builtin_operator_new(__size);
220 inline _LIBCPP_INLINE_VISIBILITY void __deallocate(void *__ptr) {
221 #ifdef _LIBCPP_HAS_NO_BUILTIN_OPERATOR_NEW_DELETE
222 ::operator delete(__ptr);
224 __builtin_operator_delete(__ptr);
228 #ifdef _LIBCPP_BAD_ARRAY_LENGTH_DEFINED
229 _LIBCPP_NORETURN inline _LIBCPP_ALWAYS_INLINE
230 void __throw_bad_array_length()
232 #ifndef _LIBCPP_NO_EXCEPTIONS
233 throw bad_array_length();
240 _LIBCPP_END_NAMESPACE_STD
242 #endif // _LIBCPP_NEW