2010-05-11 19:42:16 +00:00
|
|
|
// -*- C++ -*-
|
2021-11-17 16:25:01 -05:00
|
|
|
//===----------------------------------------------------------------------===//
|
2010-05-11 19:42:16 +00:00
|
|
|
//
|
2019-01-19 10:56:40 +00:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2010-05-11 19:42:16 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef _LIBCPP_NEW
|
|
|
|
#define _LIBCPP_NEW
|
|
|
|
|
|
|
|
/*
|
|
|
|
new synopsis
|
|
|
|
|
|
|
|
namespace std
|
|
|
|
{
|
|
|
|
|
|
|
|
class bad_alloc
|
|
|
|
: public exception
|
|
|
|
{
|
|
|
|
public:
|
2011-05-26 18:23:59 +00:00
|
|
|
bad_alloc() noexcept;
|
|
|
|
bad_alloc(const bad_alloc&) noexcept;
|
|
|
|
bad_alloc& operator=(const bad_alloc&) noexcept;
|
|
|
|
virtual const char* what() const noexcept;
|
2010-05-11 19:42:16 +00:00
|
|
|
};
|
|
|
|
|
2016-10-14 06:46:30 +00:00
|
|
|
class bad_array_new_length : public bad_alloc // C++14
|
2013-09-11 01:38:42 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
bad_array_new_length() noexcept;
|
|
|
|
};
|
|
|
|
|
2016-10-14 06:46:30 +00:00
|
|
|
enum class align_val_t : size_t {}; // C++17
|
P0722R3: Implement library support for destroying delete
Summary:
This provides the `std::destroying_delete_t` declaration in C++2a and after. (Even when the compiler doesn't support the language feature).
However, the feature test macro `__cpp_lib_destroying_delete` is only defined when we have both language support and C++2a.
Reviewers: ldionne, ckennelly, serge-sans-paille, EricWF
Reviewed By: EricWF
Subscribers: dexonsmith, riccibruno, christof, jwakely, jdoerfert, mclow.lists, ldionne, libcxx-commits
Differential Revision: https://reviews.llvm.org/D55840
llvm-svn: 361572
2019-05-23 23:46:44 +00:00
|
|
|
|
|
|
|
struct destroying_delete_t { // C++20
|
|
|
|
explicit destroying_delete_t() = default;
|
|
|
|
};
|
|
|
|
inline constexpr destroying_delete_t destroying_delete{}; // C++20
|
|
|
|
|
2019-09-26 14:51:10 +00:00
|
|
|
struct nothrow_t { explicit nothrow_t() = default; };
|
2010-05-11 19:42:16 +00:00
|
|
|
extern const nothrow_t nothrow;
|
|
|
|
typedef void (*new_handler)();
|
2011-05-26 18:23:59 +00:00
|
|
|
new_handler set_new_handler(new_handler new_p) noexcept;
|
|
|
|
new_handler get_new_handler() noexcept;
|
2010-05-11 19:42:16 +00:00
|
|
|
|
2017-11-22 19:49:03 +00:00
|
|
|
// 21.6.4, pointer optimization barrier
|
|
|
|
template <class T> constexpr T* launder(T* p) noexcept; // C++17
|
2010-05-11 19:42:16 +00:00
|
|
|
} // std
|
|
|
|
|
2021-01-07 12:29:04 +01:00
|
|
|
void* operator new(std::size_t size); // replaceable, nodiscard in C++20
|
|
|
|
void* operator new(std::size_t size, std::align_val_t alignment); // replaceable, C++17, nodiscard in C++20
|
|
|
|
void* operator new(std::size_t size, const std::nothrow_t&) noexcept; // replaceable, nodiscard in C++20
|
2016-10-14 06:46:30 +00:00
|
|
|
void* operator new(std::size_t size, std::align_val_t alignment,
|
2021-01-07 12:29:04 +01:00
|
|
|
const std::nothrow_t&) noexcept; // replaceable, C++17, nodiscard in C++20
|
2011-05-26 18:23:59 +00:00
|
|
|
void operator delete(void* ptr) noexcept; // replaceable
|
2015-02-15 05:18:55 +00:00
|
|
|
void operator delete(void* ptr, std::size_t size) noexcept; // replaceable, C++14
|
2016-10-14 06:46:30 +00:00
|
|
|
void operator delete(void* ptr, std::align_val_t alignment) noexcept; // replaceable, C++17
|
|
|
|
void operator delete(void* ptr, std::size_t size,
|
|
|
|
std::align_val_t alignment) noexcept; // replaceable, C++17
|
2011-05-26 18:23:59 +00:00
|
|
|
void operator delete(void* ptr, const std::nothrow_t&) noexcept; // replaceable
|
2016-10-14 06:46:30 +00:00
|
|
|
void operator delete(void* ptr, std:align_val_t alignment,
|
|
|
|
const std::nothrow_t&) noexcept; // replaceable, C++17
|
2010-05-11 19:42:16 +00:00
|
|
|
|
2021-01-07 12:29:04 +01:00
|
|
|
void* operator new[](std::size_t size); // replaceable, nodiscard in C++20
|
2016-10-14 06:46:30 +00:00
|
|
|
void* operator new[](std::size_t size,
|
2021-01-07 12:29:04 +01:00
|
|
|
std::align_val_t alignment) noexcept; // replaceable, C++17, nodiscard in C++20
|
|
|
|
void* operator new[](std::size_t size, const std::nothrow_t&) noexcept; // replaceable, nodiscard in C++20
|
2016-10-14 06:46:30 +00:00
|
|
|
void* operator new[](std::size_t size, std::align_val_t alignment,
|
2021-01-07 12:29:04 +01:00
|
|
|
const std::nothrow_t&) noexcept; // replaceable, C++17, nodiscard in C++20
|
2011-05-26 18:23:59 +00:00
|
|
|
void operator delete[](void* ptr) noexcept; // replaceable
|
2015-02-15 05:18:55 +00:00
|
|
|
void operator delete[](void* ptr, std::size_t size) noexcept; // replaceable, C++14
|
2016-10-14 06:46:30 +00:00
|
|
|
void operator delete[](void* ptr,
|
|
|
|
std::align_val_t alignment) noexcept; // replaceable, C++17
|
|
|
|
void operator delete[](void* ptr, std::size_t size,
|
|
|
|
std::align_val_t alignment) noexcept; // replaceable, C++17
|
2011-05-26 18:23:59 +00:00
|
|
|
void operator delete[](void* ptr, const std::nothrow_t&) noexcept; // replaceable
|
2016-10-14 06:46:30 +00:00
|
|
|
void operator delete[](void* ptr, std::align_val_t alignment,
|
|
|
|
const std::nothrow_t&) noexcept; // replaceable, C++17
|
2010-05-11 19:42:16 +00:00
|
|
|
|
2021-01-07 12:29:04 +01:00
|
|
|
void* operator new (std::size_t size, void* ptr) noexcept; // nodiscard in C++20
|
|
|
|
void* operator new[](std::size_t size, void* ptr) noexcept; // nodiscard in C++20
|
2011-05-26 18:23:59 +00:00
|
|
|
void operator delete (void* ptr, void*) noexcept;
|
|
|
|
void operator delete[](void* ptr, void*) noexcept;
|
2010-05-11 19:42:16 +00:00
|
|
|
|
|
|
|
*/
|
|
|
|
|
2022-03-25 12:55:36 -04:00
|
|
|
#include <__assert> // all public C++ headers provide the assertion handler
|
2020-11-04 15:01:25 -05:00
|
|
|
#include <__availability>
|
2021-05-19 11:57:04 -04:00
|
|
|
#include <__config>
|
2023-03-01 20:49:22 +01:00
|
|
|
#include <__exception/exception.h>
|
|
|
|
#include <__type_traits/alignment_of.h>
|
2022-12-21 00:07:17 +01:00
|
|
|
#include <__type_traits/is_function.h>
|
|
|
|
#include <__type_traits/is_same.h>
|
|
|
|
#include <__type_traits/remove_cv.h>
|
2023-01-08 14:07:44 +01:00
|
|
|
#include <__verbose_abort>
|
2020-11-12 15:14:33 -05:00
|
|
|
#include <cstddef>
|
|
|
|
#include <cstdlib>
|
2018-09-12 19:41:40 +00:00
|
|
|
#include <version>
|
2010-05-11 19:42:16 +00:00
|
|
|
|
2019-03-05 01:57:01 +00:00
|
|
|
#if defined(_LIBCPP_ABI_VCRUNTIME)
|
2017-02-10 08:57:35 +00:00
|
|
|
#include <new.h>
|
|
|
|
#endif
|
|
|
|
|
2011-10-17 20:05:10 +00:00
|
|
|
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
2022-02-01 20:16:40 -05:00
|
|
|
# pragma GCC system_header
|
2011-10-17 20:05:10 +00:00
|
|
|
#endif
|
2010-05-11 19:42:16 +00:00
|
|
|
|
2018-10-25 17:21:30 +00:00
|
|
|
#if !defined(__cpp_sized_deallocation) || __cpp_sized_deallocation < 201309L
|
|
|
|
#define _LIBCPP_HAS_NO_LANGUAGE_SIZED_DEALLOCATION
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if !defined(_LIBCPP_BUILDING_LIBRARY) && _LIBCPP_STD_VER < 14 && \
|
|
|
|
defined(_LIBCPP_HAS_NO_LANGUAGE_SIZED_DEALLOCATION)
|
2018-10-11 00:17:24 +00:00
|
|
|
# define _LIBCPP_HAS_NO_LIBRARY_SIZED_DEALLOCATION
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(_LIBCPP_HAS_NO_LIBRARY_SIZED_DEALLOCATION) || \
|
2018-10-25 17:21:30 +00:00
|
|
|
defined(_LIBCPP_HAS_NO_LANGUAGE_SIZED_DEALLOCATION)
|
2016-10-14 06:46:30 +00:00
|
|
|
# define _LIBCPP_HAS_NO_SIZED_DEALLOCATION
|
|
|
|
#endif
|
|
|
|
|
2010-05-11 19:42:16 +00:00
|
|
|
namespace std // purposefully not using versioning namespace
|
|
|
|
{
|
|
|
|
|
2019-03-05 01:57:01 +00:00
|
|
|
#if !defined(_LIBCPP_ABI_VCRUNTIME)
|
2023-06-14 10:17:50 -07:00
|
|
|
struct _LIBCPP_EXPORTED_FROM_ABI nothrow_t { explicit nothrow_t() = default; };
|
|
|
|
extern _LIBCPP_EXPORTED_FROM_ABI const nothrow_t nothrow;
|
2017-02-10 08:57:35 +00:00
|
|
|
|
2023-06-14 10:17:50 -07:00
|
|
|
class _LIBCPP_EXPORTED_FROM_ABI bad_alloc
|
2010-05-11 19:42:16 +00:00
|
|
|
: public exception
|
|
|
|
{
|
|
|
|
public:
|
2011-05-26 18:23:59 +00:00
|
|
|
bad_alloc() _NOEXCEPT;
|
2023-09-08 11:15:53 -04:00
|
|
|
_LIBCPP_HIDE_FROM_ABI bad_alloc(const bad_alloc&) _NOEXCEPT = default;
|
|
|
|
_LIBCPP_HIDE_FROM_ABI bad_alloc& operator=(const bad_alloc&) _NOEXCEPT = default;
|
2022-08-24 02:14:29 +02:00
|
|
|
~bad_alloc() _NOEXCEPT override;
|
|
|
|
const char* what() const _NOEXCEPT override;
|
2010-05-11 19:42:16 +00:00
|
|
|
};
|
|
|
|
|
2023-06-14 10:17:50 -07:00
|
|
|
class _LIBCPP_EXPORTED_FROM_ABI bad_array_new_length
|
2010-05-11 19:42:16 +00:00
|
|
|
: public bad_alloc
|
|
|
|
{
|
|
|
|
public:
|
2011-05-26 18:23:59 +00:00
|
|
|
bad_array_new_length() _NOEXCEPT;
|
2023-09-08 11:15:53 -04:00
|
|
|
_LIBCPP_HIDE_FROM_ABI bad_array_new_length(const bad_array_new_length&) _NOEXCEPT = default;
|
|
|
|
_LIBCPP_HIDE_FROM_ABI bad_array_new_length& operator=(const bad_array_new_length&) _NOEXCEPT = default;
|
2022-08-24 02:14:29 +02:00
|
|
|
~bad_array_new_length() _NOEXCEPT override;
|
|
|
|
const char* what() const _NOEXCEPT override;
|
2010-05-11 19:42:16 +00:00
|
|
|
};
|
|
|
|
|
2017-02-10 08:57:35 +00:00
|
|
|
typedef void (*new_handler)();
|
2023-06-14 10:17:50 -07:00
|
|
|
_LIBCPP_EXPORTED_FROM_ABI new_handler set_new_handler(new_handler) _NOEXCEPT;
|
|
|
|
_LIBCPP_EXPORTED_FROM_ABI new_handler get_new_handler() _NOEXCEPT;
|
2017-02-10 08:57:35 +00:00
|
|
|
|
[libcxx] Fix using the vcruntime ABI with _HAS_EXCEPTIONS=0 defined
_HAS_EXCEPTIONS=0 allows disabling the exception parts of the MS STL
and vcruntime, and e.g. compiler-rt/lib/fuzzer sets this define (to
work around issues with MS STL). If using libc++ instead of MS STL,
this define previously broke the libc++ headers.
If _HAS_EXCEPTIONS is set to 0, the vcruntime_exception.h header
doesn't define the ABI base class std::exception. If no exceptions
are going to be thrown, this probably is fine (although it also
breaks using subclasses of it as regular objects that aren't thrown),
but it requires ifdeffing out all subclasses of all exception/error
derived objects (which are sprinkled throughout the headers).
Instead, libc++ will supply an ABI compatible definition when
_HAS_EXCEPTIONS is set to 0, which will make the class hierarchies
complete.
In this build configuration, one can still create instances of
exception subclasses, and those objects will be ABI incompatible
with the ones from when _HAS_EXCEPTIONS isn't defined to 0 - but
one may argue that's a pathological/self-imposed problem in that case.
Reviewed By: #libc, ldionne
Differential Revision: https://reviews.llvm.org/D103947
2022-08-17 20:57:59 +00:00
|
|
|
#elif defined(_HAS_EXCEPTIONS) && _HAS_EXCEPTIONS == 0 // !_LIBCPP_ABI_VCRUNTIME
|
|
|
|
|
|
|
|
// When _HAS_EXCEPTIONS == 0, these complete definitions are needed,
|
|
|
|
// since they would normally be provided in vcruntime_exception.h
|
|
|
|
class bad_alloc : public exception {
|
|
|
|
public:
|
|
|
|
bad_alloc() noexcept : exception("bad allocation") {}
|
|
|
|
|
|
|
|
private:
|
|
|
|
friend class bad_array_new_length;
|
|
|
|
|
|
|
|
bad_alloc(char const* const __message) noexcept : exception(__message) {}
|
|
|
|
};
|
|
|
|
|
|
|
|
class bad_array_new_length : public bad_alloc {
|
|
|
|
public:
|
|
|
|
bad_array_new_length() noexcept : bad_alloc("bad array new length") {}
|
|
|
|
};
|
2022-08-18 16:49:06 -04:00
|
|
|
#endif // defined(_LIBCPP_ABI_VCRUNTIME) && defined(_HAS_EXCEPTIONS) && _HAS_EXCEPTIONS == 0
|
2017-02-10 08:57:35 +00:00
|
|
|
|
2023-06-14 10:17:50 -07:00
|
|
|
_LIBCPP_NORETURN _LIBCPP_EXPORTED_FROM_ABI void __throw_bad_alloc(); // not in C++ spec
|
2016-08-25 15:09:01 +00:00
|
|
|
|
2021-10-18 19:12:42 +01:00
|
|
|
_LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY
|
|
|
|
void __throw_bad_array_new_length()
|
|
|
|
{
|
2023-02-02 11:47:01 +01:00
|
|
|
#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
|
2021-10-18 19:12:42 +01:00
|
|
|
throw bad_array_new_length();
|
|
|
|
#else
|
2023-03-16 15:05:49 +01:00
|
|
|
_LIBCPP_VERBOSE_ABORT("bad_array_new_length was thrown in -fno-exceptions mode");
|
2021-10-18 19:12:42 +01:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2018-10-11 00:17:24 +00:00
|
|
|
#if !defined(_LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION) && \
|
2019-03-05 01:57:01 +00:00
|
|
|
!defined(_LIBCPP_ABI_VCRUNTIME)
|
2016-10-14 06:46:30 +00:00
|
|
|
#ifndef _LIBCPP_CXX03_LANG
|
2023-08-19 15:15:47 -07:00
|
|
|
enum class align_val_t : size_t { };
|
2016-10-14 06:46:30 +00:00
|
|
|
#else
|
|
|
|
enum align_val_t { __zero = 0, __max = (size_t)-1 };
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2023-02-14 00:56:09 +01:00
|
|
|
#if _LIBCPP_STD_VER >= 20
|
P0722R3: Implement library support for destroying delete
Summary:
This provides the `std::destroying_delete_t` declaration in C++2a and after. (Even when the compiler doesn't support the language feature).
However, the feature test macro `__cpp_lib_destroying_delete` is only defined when we have both language support and C++2a.
Reviewers: ldionne, ckennelly, serge-sans-paille, EricWF
Reviewed By: EricWF
Subscribers: dexonsmith, riccibruno, christof, jwakely, jdoerfert, mclow.lists, ldionne, libcxx-commits
Differential Revision: https://reviews.llvm.org/D55840
llvm-svn: 361572
2019-05-23 23:46:44 +00:00
|
|
|
// Enable the declaration even if the compiler doesn't support the language
|
|
|
|
// feature.
|
|
|
|
struct destroying_delete_t {
|
|
|
|
explicit destroying_delete_t() = default;
|
|
|
|
};
|
2021-09-22 09:35:32 -04:00
|
|
|
inline constexpr destroying_delete_t destroying_delete{};
|
2023-02-14 00:56:09 +01:00
|
|
|
#endif // _LIBCPP_STD_VER >= 20
|
P0722R3: Implement library support for destroying delete
Summary:
This provides the `std::destroying_delete_t` declaration in C++2a and after. (Even when the compiler doesn't support the language feature).
However, the feature test macro `__cpp_lib_destroying_delete` is only defined when we have both language support and C++2a.
Reviewers: ldionne, ckennelly, serge-sans-paille, EricWF
Reviewed By: EricWF
Subscribers: dexonsmith, riccibruno, christof, jwakely, jdoerfert, mclow.lists, ldionne, libcxx-commits
Differential Revision: https://reviews.llvm.org/D55840
llvm-svn: 361572
2019-05-23 23:46:44 +00:00
|
|
|
|
2021-12-02 14:12:51 +01:00
|
|
|
} // namespace std
|
2010-05-11 19:42:16 +00:00
|
|
|
|
2017-01-02 23:27:42 +00:00
|
|
|
#if defined(_LIBCPP_CXX03_LANG)
|
2016-10-14 06:46:30 +00:00
|
|
|
#define _THROW_BAD_ALLOC throw(std::bad_alloc)
|
|
|
|
#else
|
|
|
|
#define _THROW_BAD_ALLOC
|
2011-05-26 18:23:59 +00:00
|
|
|
#endif
|
2016-10-14 06:46:30 +00:00
|
|
|
|
2019-03-05 01:57:01 +00:00
|
|
|
#if !defined(_LIBCPP_ABI_VCRUNTIME)
|
2017-02-10 08:57:35 +00:00
|
|
|
|
2017-12-04 23:03:42 +00:00
|
|
|
_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new(std::size_t __sz) _THROW_BAD_ALLOC;
|
2019-02-26 06:34:42 +00:00
|
|
|
_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new(std::size_t __sz, const std::nothrow_t&) _NOEXCEPT _LIBCPP_NOALIAS;
|
2016-11-16 22:18:10 +00:00
|
|
|
_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete(void* __p) _NOEXCEPT;
|
|
|
|
_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete(void* __p, const std::nothrow_t&) _NOEXCEPT;
|
2018-10-11 00:17:24 +00:00
|
|
|
#ifndef _LIBCPP_HAS_NO_LIBRARY_SIZED_DEALLOCATION
|
2017-05-04 17:08:54 +00:00
|
|
|
_LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_AVAILABILITY_SIZED_NEW_DELETE void operator delete(void* __p, std::size_t __sz) _NOEXCEPT;
|
2015-02-20 06:13:05 +00:00
|
|
|
#endif
|
2011-05-26 18:23:59 +00:00
|
|
|
|
2017-12-04 23:03:42 +00:00
|
|
|
_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new[](std::size_t __sz) _THROW_BAD_ALLOC;
|
2019-02-26 06:34:42 +00:00
|
|
|
_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new[](std::size_t __sz, const std::nothrow_t&) _NOEXCEPT _LIBCPP_NOALIAS;
|
2016-11-16 22:18:10 +00:00
|
|
|
_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete[](void* __p) _NOEXCEPT;
|
|
|
|
_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete[](void* __p, const std::nothrow_t&) _NOEXCEPT;
|
2018-10-11 00:17:24 +00:00
|
|
|
#ifndef _LIBCPP_HAS_NO_LIBRARY_SIZED_DEALLOCATION
|
2017-05-04 17:08:54 +00:00
|
|
|
_LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_AVAILABILITY_SIZED_NEW_DELETE void operator delete[](void* __p, std::size_t __sz) _NOEXCEPT;
|
2015-02-20 06:13:05 +00:00
|
|
|
#endif
|
2013-08-12 18:38:34 +00:00
|
|
|
|
2018-10-11 00:17:24 +00:00
|
|
|
#ifndef _LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION
|
2017-12-04 23:03:42 +00:00
|
|
|
_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new(std::size_t __sz, std::align_val_t) _THROW_BAD_ALLOC;
|
2019-02-26 06:34:42 +00:00
|
|
|
_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new(std::size_t __sz, std::align_val_t, const std::nothrow_t&) _NOEXCEPT _LIBCPP_NOALIAS;
|
2017-06-30 18:50:23 +00:00
|
|
|
_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete(void* __p, std::align_val_t) _NOEXCEPT;
|
|
|
|
_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete(void* __p, std::align_val_t, const std::nothrow_t&) _NOEXCEPT;
|
2018-10-11 00:17:24 +00:00
|
|
|
#ifndef _LIBCPP_HAS_NO_LIBRARY_SIZED_DEALLOCATION
|
2017-06-30 18:50:23 +00:00
|
|
|
_LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_AVAILABILITY_SIZED_NEW_DELETE void operator delete(void* __p, std::size_t __sz, std::align_val_t) _NOEXCEPT;
|
2016-10-14 06:46:30 +00:00
|
|
|
#endif
|
|
|
|
|
2017-12-04 23:03:42 +00:00
|
|
|
_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new[](std::size_t __sz, std::align_val_t) _THROW_BAD_ALLOC;
|
2019-02-26 06:34:42 +00:00
|
|
|
_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new[](std::size_t __sz, std::align_val_t, const std::nothrow_t&) _NOEXCEPT _LIBCPP_NOALIAS;
|
2017-06-30 18:50:23 +00:00
|
|
|
_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete[](void* __p, std::align_val_t) _NOEXCEPT;
|
|
|
|
_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete[](void* __p, std::align_val_t, const std::nothrow_t&) _NOEXCEPT;
|
2018-10-11 00:17:24 +00:00
|
|
|
#ifndef _LIBCPP_HAS_NO_LIBRARY_SIZED_DEALLOCATION
|
2017-06-30 18:50:23 +00:00
|
|
|
_LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_AVAILABILITY_SIZED_NEW_DELETE void operator delete[](void* __p, std::size_t __sz, std::align_val_t) _NOEXCEPT;
|
2016-10-14 06:46:30 +00:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2017-12-04 23:03:42 +00:00
|
|
|
_LIBCPP_NODISCARD_AFTER_CXX17 inline _LIBCPP_INLINE_VISIBILITY void* operator new (std::size_t, void* __p) _NOEXCEPT {return __p;}
|
|
|
|
_LIBCPP_NODISCARD_AFTER_CXX17 inline _LIBCPP_INLINE_VISIBILITY void* operator new[](std::size_t, void* __p) _NOEXCEPT {return __p;}
|
2013-10-04 22:09:00 +00:00
|
|
|
inline _LIBCPP_INLINE_VISIBILITY void operator delete (void*, void*) _NOEXCEPT {}
|
|
|
|
inline _LIBCPP_INLINE_VISIBILITY void operator delete[](void*, void*) _NOEXCEPT {}
|
2010-05-11 19:42:16 +00:00
|
|
|
|
2019-03-05 01:57:01 +00:00
|
|
|
#endif // !_LIBCPP_ABI_VCRUNTIME
|
2017-02-10 08:57:35 +00:00
|
|
|
|
2014-06-04 19:54:15 +00:00
|
|
|
_LIBCPP_BEGIN_NAMESPACE_STD
|
|
|
|
|
2018-03-22 04:42:56 +00:00
|
|
|
_LIBCPP_CONSTEXPR inline _LIBCPP_INLINE_VISIBILITY bool __is_overaligned_for_new(size_t __align) _NOEXCEPT {
|
|
|
|
#ifdef __STDCPP_DEFAULT_NEW_ALIGNMENT__
|
|
|
|
return __align > __STDCPP_DEFAULT_NEW_ALIGNMENT__;
|
|
|
|
#else
|
|
|
|
return __align > alignment_of<max_align_t>::value;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2020-09-25 09:24:14 -04:00
|
|
|
template <class ..._Args>
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
void* __libcpp_operator_new(_Args ...__args) {
|
|
|
|
#if __has_builtin(__builtin_operator_new) && __has_builtin(__builtin_operator_delete)
|
|
|
|
return __builtin_operator_new(__args...);
|
2018-03-22 04:42:56 +00:00
|
|
|
#else
|
2020-09-25 09:24:14 -04:00
|
|
|
return ::operator new(__args...);
|
2014-06-04 19:54:15 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2020-09-25 09:24:14 -04:00
|
|
|
template <class ..._Args>
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
void __libcpp_operator_delete(_Args ...__args) {
|
|
|
|
#if __has_builtin(__builtin_operator_new) && __has_builtin(__builtin_operator_delete)
|
|
|
|
__builtin_operator_delete(__args...);
|
2018-10-25 17:21:30 +00:00
|
|
|
#else
|
2020-09-25 09:24:14 -04:00
|
|
|
::operator delete(__args...);
|
2018-10-25 17:21:30 +00:00
|
|
|
#endif
|
2020-09-25 09:24:14 -04:00
|
|
|
}
|
2018-10-25 17:21:30 +00:00
|
|
|
|
2020-09-25 09:24:14 -04:00
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
|
|
|
void *__libcpp_allocate(size_t __size, size_t __align) {
|
|
|
|
#ifndef _LIBCPP_HAS_NO_ALIGNED_ALLOCATION
|
|
|
|
if (__is_overaligned_for_new(__align)) {
|
|
|
|
const align_val_t __align_val = static_cast<align_val_t>(__align);
|
|
|
|
return __libcpp_operator_new(__size, __align_val);
|
2020-09-17 12:06:13 -04:00
|
|
|
}
|
2018-10-25 17:21:30 +00:00
|
|
|
#endif
|
|
|
|
|
2020-09-25 09:24:14 -04:00
|
|
|
(void)__align;
|
|
|
|
return __libcpp_operator_new(__size);
|
|
|
|
}
|
2018-10-25 17:21:30 +00:00
|
|
|
|
2020-09-25 09:24:14 -04:00
|
|
|
template <class ..._Args>
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
void __do_deallocate_handle_size(void *__ptr, size_t __size, _Args ...__args) {
|
2018-10-25 17:21:30 +00:00
|
|
|
#ifdef _LIBCPP_HAS_NO_SIZED_DEALLOCATION
|
2020-09-25 09:24:14 -04:00
|
|
|
(void)__size;
|
[libc++] Add custom clang-tidy checks
Reviewed By: #libc, ldionne
Spies: jwakely, beanz, smeenai, cfe-commits, tschuett, avogelsgesang, Mordante, sstefan1, libcxx-commits, ldionne, mgorny, arichardson, miyuki
Differential Revision: https://reviews.llvm.org/D131963
2022-08-13 22:33:12 +02:00
|
|
|
return std::__libcpp_operator_delete(__ptr, __args...);
|
2018-10-25 17:21:30 +00:00
|
|
|
#else
|
[libc++] Add custom clang-tidy checks
Reviewed By: #libc, ldionne
Spies: jwakely, beanz, smeenai, cfe-commits, tschuett, avogelsgesang, Mordante, sstefan1, libcxx-commits, ldionne, mgorny, arichardson, miyuki
Differential Revision: https://reviews.llvm.org/D131963
2022-08-13 22:33:12 +02:00
|
|
|
return std::__libcpp_operator_delete(__ptr, __size, __args...);
|
2018-10-25 17:21:30 +00:00
|
|
|
#endif
|
2020-09-25 09:24:14 -04:00
|
|
|
}
|
2018-10-25 17:21:30 +00:00
|
|
|
|
2020-09-25 09:24:14 -04:00
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
|
|
|
void __libcpp_deallocate(void* __ptr, size_t __size, size_t __align) {
|
2020-09-17 12:06:13 -04:00
|
|
|
#if defined(_LIBCPP_HAS_NO_ALIGNED_ALLOCATION)
|
2020-09-25 09:24:14 -04:00
|
|
|
(void)__align;
|
2020-09-17 12:06:13 -04:00
|
|
|
return __do_deallocate_handle_size(__ptr, __size);
|
2018-10-25 17:21:30 +00:00
|
|
|
#else
|
2020-09-17 12:06:13 -04:00
|
|
|
if (__is_overaligned_for_new(__align)) {
|
|
|
|
const align_val_t __align_val = static_cast<align_val_t>(__align);
|
|
|
|
return __do_deallocate_handle_size(__ptr, __size, __align_val);
|
|
|
|
} else {
|
|
|
|
return __do_deallocate_handle_size(__ptr, __size);
|
|
|
|
}
|
2018-10-25 17:21:30 +00:00
|
|
|
#endif
|
2020-09-25 09:24:14 -04:00
|
|
|
}
|
2018-10-25 17:21:30 +00:00
|
|
|
|
2020-09-25 09:24:14 -04:00
|
|
|
inline _LIBCPP_INLINE_VISIBILITY void __libcpp_deallocate_unsized(void* __ptr, size_t __align) {
|
2020-09-17 12:06:13 -04:00
|
|
|
#if defined(_LIBCPP_HAS_NO_ALIGNED_ALLOCATION)
|
2020-09-25 09:24:14 -04:00
|
|
|
(void)__align;
|
|
|
|
return __libcpp_operator_delete(__ptr);
|
2014-06-04 19:54:15 +00:00
|
|
|
#else
|
2020-09-17 12:06:13 -04:00
|
|
|
if (__is_overaligned_for_new(__align)) {
|
|
|
|
const align_val_t __align_val = static_cast<align_val_t>(__align);
|
2020-09-25 09:24:14 -04:00
|
|
|
return __libcpp_operator_delete(__ptr, __align_val);
|
2020-09-17 12:06:13 -04:00
|
|
|
} else {
|
2020-09-25 09:24:14 -04:00
|
|
|
return __libcpp_operator_delete(__ptr);
|
2020-09-17 12:06:13 -04:00
|
|
|
}
|
2014-06-04 19:54:15 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2017-11-22 19:49:03 +00:00
|
|
|
template <class _Tp>
|
2021-08-31 10:29:22 -04:00
|
|
|
_LIBCPP_NODISCARD_AFTER_CXX17 inline _LIBCPP_HIDE_FROM_ABI
|
2017-11-22 19:49:03 +00:00
|
|
|
_LIBCPP_CONSTEXPR _Tp* __launder(_Tp* __p) _NOEXCEPT
|
|
|
|
{
|
|
|
|
static_assert (!(is_function<_Tp>::value), "can't launder functions" );
|
2022-09-06 00:33:34 +02:00
|
|
|
static_assert (!(is_same<void, __remove_cv_t<_Tp> >::value), "can't launder cv-void" );
|
2017-11-22 19:49:03 +00:00
|
|
|
return __builtin_launder(__p);
|
|
|
|
}
|
|
|
|
|
2023-02-14 00:56:09 +01:00
|
|
|
#if _LIBCPP_STD_VER >= 17
|
2017-11-22 19:49:03 +00:00
|
|
|
template <class _Tp>
|
2021-08-31 10:29:22 -04:00
|
|
|
_LIBCPP_NODISCARD_AFTER_CXX17 inline _LIBCPP_HIDE_FROM_ABI
|
2017-11-22 19:49:03 +00:00
|
|
|
constexpr _Tp* launder(_Tp* __p) noexcept
|
|
|
|
{
|
2017-11-23 01:25:03 +00:00
|
|
|
return _VSTD::__launder(__p);
|
2017-11-22 19:49:03 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2023-02-14 00:56:09 +01:00
|
|
|
#if _LIBCPP_STD_VER >= 17
|
2022-06-22 21:10:57 +02:00
|
|
|
|
|
|
|
#if defined(__GCC_DESTRUCTIVE_SIZE) && defined(__GCC_CONSTRUCTIVE_SIZE)
|
|
|
|
|
|
|
|
inline constexpr size_t hardware_destructive_interference_size = __GCC_DESTRUCTIVE_SIZE;
|
|
|
|
inline constexpr size_t hardware_constructive_interference_size = __GCC_CONSTRUCTIVE_SIZE;
|
|
|
|
|
|
|
|
#endif // defined(__GCC_DESTRUCTIVE_SIZE) && defined(__GCC_CONSTRUCTIVE_SIZE)
|
|
|
|
|
2023-02-14 00:56:09 +01:00
|
|
|
#endif // _LIBCPP_STD_VER >= 17
|
2022-06-22 21:10:57 +02:00
|
|
|
|
2014-06-04 19:54:15 +00:00
|
|
|
_LIBCPP_END_NAMESPACE_STD
|
|
|
|
|
2023-07-07 14:12:05 -07:00
|
|
|
#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
|
|
|
|
# include <exception>
|
|
|
|
# include <type_traits>
|
|
|
|
#endif
|
|
|
|
|
2021-04-20 12:03:32 -04:00
|
|
|
#endif // _LIBCPP_NEW
|