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
|
2023-11-23 11:11:44 -05:00
|
|
|
template <class T> [[nodiscard]] constexpr T* launder(T* p) noexcept; // C++17, nodiscard since C++20
|
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
|
|
|
|
2024-08-28 21:35:57 +08:00
|
|
|
void* operator new (std::size_t size, void* ptr) noexcept; // nodiscard in C++20, constexpr since C++26
|
|
|
|
void* operator new[](std::size_t size, void* ptr) noexcept; // nodiscard in C++20, constexpr since C++26
|
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
|
|
|
|
|
|
|
*/
|
|
|
|
|
2024-12-21 13:01:48 +01:00
|
|
|
#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
|
|
|
|
# include <__cxx03/new>
|
|
|
|
#else
|
2024-12-10 16:02:12 +01:00
|
|
|
# include <__config>
|
2024-12-13 14:17:56 -05:00
|
|
|
# include <__new/align_val_t.h>
|
|
|
|
# include <__new/allocate.h>
|
|
|
|
# include <__new/exceptions.h>
|
|
|
|
# include <__new/global_new_delete.h>
|
|
|
|
# include <__new/new_handler.h>
|
|
|
|
# include <__new/nothrow_t.h>
|
|
|
|
# include <__new/placement_new_delete.h>
|
[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
|
|
|
|
2024-12-13 14:17:56 -05:00
|
|
|
# if _LIBCPP_STD_VER >= 17
|
|
|
|
# include <__new/interference_size.h>
|
|
|
|
# include <__new/launder.h>
|
2016-10-14 06:46:30 +00:00
|
|
|
# endif
|
|
|
|
|
2024-12-10 16:02:12 +01:00
|
|
|
# if _LIBCPP_STD_VER >= 20
|
2024-12-13 14:17:56 -05:00
|
|
|
# include <__new/destroying_delete_t.h>
|
2024-12-10 16:02:12 +01:00
|
|
|
# endif
|
2014-06-04 19:54:15 +00:00
|
|
|
|
2024-12-13 14:17:56 -05:00
|
|
|
// feature-test macros
|
|
|
|
# include <version>
|
2017-11-22 19:49:03 +00:00
|
|
|
|
2024-12-13 14:17:56 -05:00
|
|
|
# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
|
|
|
# pragma GCC system_header
|
2024-12-10 16:02:12 +01:00
|
|
|
# endif
|
2017-11-22 19:49:03 +00:00
|
|
|
|
2024-12-10 16:02:12 +01:00
|
|
|
# if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
|
|
|
|
# include <cstddef>
|
|
|
|
# include <cstdlib>
|
|
|
|
# include <type_traits>
|
|
|
|
# endif
|
2024-12-21 13:01:48 +01:00
|
|
|
#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
|
2023-07-07 14:12:05 -07:00
|
|
|
|
2021-04-20 12:03:32 -04:00
|
|
|
#endif // _LIBCPP_NEW
|