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 // C++14
33 bad_array_length() noexcept;
36 class bad_array_new_length : public bad_alloc
39 bad_array_new_length() noexcept;
43 extern const nothrow_t nothrow;
44 typedef void (*new_handler)();
45 new_handler set_new_handler(new_handler new_p) noexcept;
46 new_handler get_new_handler() noexcept;
50 void* operator new(std::size_t size); // replaceable
51 void* operator new(std::size_t size, const std::nothrow_t&) noexcept; // replaceable
52 void operator delete(void* ptr) noexcept; // replaceable
53 void operator delete(void* ptr, std::size_t size) noexcept; // replaceable, C++14
54 void operator delete(void* ptr, const std::nothrow_t&) noexcept; // replaceable
55 void operator delete(void* ptr, std::size_t size,
56 const std::nothrow_t&) noexcept; // replaceable, C++14
58 void* operator new[](std::size_t size); // replaceable
59 void* operator new[](std::size_t size, const std::nothrow_t&) noexcept; // replaceable
60 void operator delete[](void* ptr) noexcept; // replaceable
61 void operator delete[](void* ptr, std::size_t size) noexcept; // replaceable, C++14
62 void operator delete[](void* ptr, const std::nothrow_t&) noexcept; // replaceable
63 void operator delete[](void* ptr, std::size_t size,
64 const std::nothrow_t&) noexcept; // replaceable, C++14
66 void* operator new (std::size_t size, void* ptr) noexcept;
67 void* operator new[](std::size_t size, void* ptr) noexcept;
68 void operator delete (void* ptr, void*) noexcept;
69 void operator delete[](void* ptr, void*) noexcept;
77 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
78 #pragma GCC system_header
81 namespace std // purposefully not using versioning namespace
84 class _LIBCPP_EXCEPTION_ABI bad_alloc
88 bad_alloc() _NOEXCEPT;
89 virtual ~bad_alloc() _NOEXCEPT;
90 virtual const char* what() const _NOEXCEPT;
93 class _LIBCPP_EXCEPTION_ABI bad_array_new_length
97 bad_array_new_length() _NOEXCEPT;
98 virtual ~bad_array_new_length() _NOEXCEPT;
99 virtual const char* what() const _NOEXCEPT;
102 #if defined(_LIBCPP_BUILDING_NEW) || (_LIBCPP_STD_VER > 11)
104 class _LIBCPP_EXCEPTION_ABI bad_array_length
108 bad_array_length() _NOEXCEPT;
109 virtual ~bad_array_length() _NOEXCEPT;
110 virtual const char* what() const _NOEXCEPT;
113 #define _LIBCPP_BAD_ARRAY_LENGTH_DEFINED
115 #endif // defined(_LIBCPP_BUILDING_NEW) || (_LIBCPP_STD_VER > 11)
117 _LIBCPP_FUNC_VIS void __throw_bad_alloc(); // not in C++ spec
119 struct _LIBCPP_TYPE_VIS nothrow_t {};
120 extern _LIBCPP_FUNC_VIS const nothrow_t nothrow;
121 typedef void (*new_handler)();
122 _LIBCPP_FUNC_VIS new_handler set_new_handler(new_handler) _NOEXCEPT;
123 _LIBCPP_FUNC_VIS new_handler get_new_handler() _NOEXCEPT;
127 #if defined(_WIN32) && !defined(cxx_EXPORTS)
128 # define _LIBCPP_NEW_DELETE_VIS _LIBCPP_FUNC_VIS_ONLY
130 # define _LIBCPP_NEW_DELETE_VIS _LIBCPP_FUNC_VIS
133 _LIBCPP_NEW_DELETE_VIS void* operator new(std::size_t __sz)
134 #if !__has_feature(cxx_noexcept)
135 throw(std::bad_alloc)
138 _LIBCPP_NEW_DELETE_VIS void* operator new(std::size_t __sz, const std::nothrow_t&) _NOEXCEPT _NOALIAS;
139 _LIBCPP_NEW_DELETE_VIS void operator delete(void* __p) _NOEXCEPT;
140 _LIBCPP_NEW_DELETE_VIS void operator delete(void* __p, std::size_t __sz) _NOEXCEPT;
141 _LIBCPP_NEW_DELETE_VIS void operator delete(void* __p, const std::nothrow_t&) _NOEXCEPT;
142 _LIBCPP_NEW_DELETE_VIS void operator delete(void* __p, std::size_t __sz, const std::nothrow_t&) _NOEXCEPT;
144 _LIBCPP_NEW_DELETE_VIS void* operator new[](std::size_t __sz)
145 #if !__has_feature(cxx_noexcept)
146 throw(std::bad_alloc)
149 _LIBCPP_NEW_DELETE_VIS void* operator new[](std::size_t __sz, const std::nothrow_t&) _NOEXCEPT _NOALIAS;
150 _LIBCPP_NEW_DELETE_VIS void operator delete[](void* __p) _NOEXCEPT;
151 _LIBCPP_NEW_DELETE_VIS void operator delete[](void* __p, std::size_t __sz) _NOEXCEPT;
152 _LIBCPP_NEW_DELETE_VIS void operator delete[](void* __p, const std::nothrow_t&) _NOEXCEPT;
153 _LIBCPP_NEW_DELETE_VIS void operator delete[](void* __p, std::size_t __sz, const std::nothrow_t&) _NOEXCEPT;
155 inline _LIBCPP_INLINE_VISIBILITY void* operator new (std::size_t, void* __p) _NOEXCEPT {return __p;}
156 inline _LIBCPP_INLINE_VISIBILITY void* operator new[](std::size_t, void* __p) _NOEXCEPT {return __p;}
157 inline _LIBCPP_INLINE_VISIBILITY void operator delete (void*, void*) _NOEXCEPT {}
158 inline _LIBCPP_INLINE_VISIBILITY void operator delete[](void*, void*) _NOEXCEPT {}
160 _LIBCPP_BEGIN_NAMESPACE_STD
162 inline _LIBCPP_INLINE_VISIBILITY void *__allocate(size_t __size) {
163 #ifdef _LIBCPP_HAS_NO_BUILTIN_OPERATOR_NEW_DELETE
164 return ::operator new(__size);
166 return __builtin_operator_new(__size);
170 inline _LIBCPP_INLINE_VISIBILITY void __deallocate(void *__ptr) {
171 #ifdef _LIBCPP_HAS_NO_BUILTIN_OPERATOR_NEW_DELETE
172 ::operator delete(__ptr);
174 __builtin_operator_delete(__ptr);
178 _LIBCPP_END_NAMESPACE_STD
180 #endif // _LIBCPP_NEW