mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-06-27 23:08:31 +00:00
Upgrade to 2022-era LLVM LIBCXX
This commit is contained in:
parent
2f4ca71f26
commit
8e68384e15
2078 changed files with 165657 additions and 65010 deletions
182
third_party/libcxx/any
vendored
182
third_party/libcxx/any
vendored
|
@ -1,5 +1,5 @@
|
|||
// -*- C++ -*-
|
||||
//===------------------------------ any -----------------------------------===//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
|
@ -80,38 +80,61 @@ namespace std {
|
|||
|
||||
*/
|
||||
|
||||
#include "third_party/libcxx/experimental/__config"
|
||||
#include "third_party/libcxx/memory"
|
||||
#include "third_party/libcxx/new"
|
||||
#include "third_party/libcxx/typeinfo"
|
||||
#include "third_party/libcxx/type_traits"
|
||||
#include "third_party/libcxx/cstdlib"
|
||||
#include "third_party/libcxx/version"
|
||||
#include <__assert> // all public C++ headers provide the assertion handler
|
||||
#include <__availability>
|
||||
#include <__config>
|
||||
#include <__memory/allocator.h>
|
||||
#include <__memory/allocator_destructor.h>
|
||||
#include <__memory/allocator_traits.h>
|
||||
#include <__memory/unique_ptr.h>
|
||||
#include <__type_traits/add_const.h>
|
||||
#include <__type_traits/add_pointer.h>
|
||||
#include <__type_traits/aligned_storage.h>
|
||||
#include <__type_traits/alignment_of.h>
|
||||
#include <__type_traits/conditional.h>
|
||||
#include <__type_traits/decay.h>
|
||||
#include <__type_traits/is_constructible.h>
|
||||
#include <__type_traits/is_copy_constructible.h>
|
||||
#include <__type_traits/is_function.h>
|
||||
#include <__type_traits/is_nothrow_move_constructible.h>
|
||||
#include <__type_traits/is_reference.h>
|
||||
#include <__type_traits/is_same.h>
|
||||
#include <__type_traits/remove_cv.h>
|
||||
#include <__type_traits/remove_cvref.h>
|
||||
#include <__type_traits/remove_reference.h>
|
||||
#include <__utility/forward.h>
|
||||
#include <__utility/in_place.h>
|
||||
#include <__utility/move.h>
|
||||
#include <__utility/unreachable.h>
|
||||
#include <__verbose_abort>
|
||||
#include <initializer_list>
|
||||
#include <typeinfo>
|
||||
#include <version>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
#pragma GCC system_header
|
||||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
namespace std {
|
||||
class _LIBCPP_EXCEPTION_ABI _LIBCPP_AVAILABILITY_BAD_ANY_CAST bad_any_cast : public bad_cast
|
||||
{
|
||||
public:
|
||||
virtual const char* what() const _NOEXCEPT;
|
||||
const char* what() const _NOEXCEPT override;
|
||||
};
|
||||
} // namespace std
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
#if _LIBCPP_STD_VER > 14
|
||||
#if _LIBCPP_STD_VER >= 17
|
||||
|
||||
_LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY
|
||||
_LIBCPP_AVAILABILITY_THROW_BAD_ANY_CAST
|
||||
void __throw_bad_any_cast()
|
||||
{
|
||||
#ifndef _LIBCPP_NO_EXCEPTIONS
|
||||
#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
|
||||
throw bad_any_cast();
|
||||
#else
|
||||
_VSTD::abort();
|
||||
_LIBCPP_VERBOSE_ABORT("bad_any_cast was thrown in -fno-exceptions mode");
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -129,7 +152,9 @@ add_pointer_t<_ValueType> any_cast(any *) _NOEXCEPT;
|
|||
|
||||
namespace __any_imp
|
||||
{
|
||||
_LIBCPP_SUPPRESS_DEPRECATED_PUSH
|
||||
using _Buffer = aligned_storage_t<3*sizeof(void*), alignment_of<void*>::value>;
|
||||
_LIBCPP_SUPPRESS_DEPRECATED_POP
|
||||
|
||||
template <class _Tp>
|
||||
using _IsSmallObject = integral_constant<bool
|
||||
|
@ -157,14 +182,14 @@ namespace __any_imp
|
|||
template <class _Tp>
|
||||
inline _LIBCPP_INLINE_VISIBILITY
|
||||
constexpr const void* __get_fallback_typeid() {
|
||||
return &__unique_typeinfo<decay_t<_Tp>>::__id;
|
||||
return &__unique_typeinfo<remove_cv_t<remove_reference_t<_Tp>>>::__id;
|
||||
}
|
||||
|
||||
template <class _Tp>
|
||||
inline _LIBCPP_INLINE_VISIBILITY
|
||||
bool __compare_typeid(type_info const* __id, const void* __fallback_id)
|
||||
{
|
||||
#if !defined(_LIBCPP_NO_RTTI)
|
||||
#if !defined(_LIBCPP_HAS_NO_RTTI)
|
||||
if (__id && *__id == typeid(_Tp))
|
||||
return true;
|
||||
#endif
|
||||
|
@ -184,18 +209,18 @@ class _LIBCPP_TEMPLATE_VIS any
|
|||
public:
|
||||
// construct/destruct
|
||||
_LIBCPP_INLINE_VISIBILITY
|
||||
constexpr any() _NOEXCEPT : __h(nullptr) {}
|
||||
constexpr any() _NOEXCEPT : __h_(nullptr) {}
|
||||
|
||||
_LIBCPP_INLINE_VISIBILITY
|
||||
any(any const & __other) : __h(nullptr)
|
||||
any(any const & __other) : __h_(nullptr)
|
||||
{
|
||||
if (__other.__h) __other.__call(_Action::_Copy, this);
|
||||
if (__other.__h_) __other.__call(_Action::_Copy, this);
|
||||
}
|
||||
|
||||
_LIBCPP_INLINE_VISIBILITY
|
||||
any(any && __other) _NOEXCEPT : __h(nullptr)
|
||||
any(any && __other) _NOEXCEPT : __h_(nullptr)
|
||||
{
|
||||
if (__other.__h) __other.__call(_Action::_Move, this);
|
||||
if (__other.__h_) __other.__call(_Action::_Move, this);
|
||||
}
|
||||
|
||||
template <
|
||||
|
@ -261,7 +286,7 @@ public:
|
|||
is_copy_constructible<_Tp>::value>
|
||||
>
|
||||
_LIBCPP_INLINE_VISIBILITY
|
||||
_Tp& emplace(_Args&&... args);
|
||||
_Tp& emplace(_Args&&...);
|
||||
|
||||
template <class _ValueType, class _Up, class ..._Args,
|
||||
class _Tp = decay_t<_ValueType>,
|
||||
|
@ -274,19 +299,19 @@ public:
|
|||
|
||||
// 6.3.3 any modifiers
|
||||
_LIBCPP_INLINE_VISIBILITY
|
||||
void reset() _NOEXCEPT { if (__h) this->__call(_Action::_Destroy); }
|
||||
void reset() _NOEXCEPT { if (__h_) this->__call(_Action::_Destroy); }
|
||||
|
||||
_LIBCPP_INLINE_VISIBILITY
|
||||
void swap(any & __rhs) _NOEXCEPT;
|
||||
|
||||
// 6.3.4 any observers
|
||||
_LIBCPP_INLINE_VISIBILITY
|
||||
bool has_value() const _NOEXCEPT { return __h != nullptr; }
|
||||
bool has_value() const _NOEXCEPT { return __h_ != nullptr; }
|
||||
|
||||
#if !defined(_LIBCPP_NO_RTTI)
|
||||
#if !defined(_LIBCPP_HAS_NO_RTTI)
|
||||
_LIBCPP_INLINE_VISIBILITY
|
||||
const type_info & type() const _NOEXCEPT {
|
||||
if (__h) {
|
||||
if (__h_) {
|
||||
return *static_cast<type_info const *>(this->__call(_Action::_TypeInfo));
|
||||
} else {
|
||||
return typeid(void);
|
||||
|
@ -300,7 +325,7 @@ private:
|
|||
const void* __fallback_info);
|
||||
|
||||
union _Storage {
|
||||
constexpr _Storage() : __ptr(nullptr) {}
|
||||
_LIBCPP_HIDE_FROM_ABI constexpr _Storage() : __ptr(nullptr) {}
|
||||
void * __ptr;
|
||||
__any_imp::_Buffer __buf;
|
||||
};
|
||||
|
@ -310,7 +335,7 @@ private:
|
|||
type_info const * __info = nullptr,
|
||||
const void* __fallback_info = nullptr) const
|
||||
{
|
||||
return __h(__a, this, __other, __info, __fallback_info);
|
||||
return __h_(__a, this, __other, __info, __fallback_info);
|
||||
}
|
||||
|
||||
_LIBCPP_INLINE_VISIBILITY
|
||||
|
@ -318,7 +343,7 @@ private:
|
|||
type_info const * __info = nullptr,
|
||||
const void* __fallback_info = nullptr)
|
||||
{
|
||||
return __h(__a, this, __other, __info, __fallback_info);
|
||||
return __h_(__a, this, __other, __info, __fallback_info);
|
||||
}
|
||||
|
||||
template <class>
|
||||
|
@ -334,8 +359,8 @@ private:
|
|||
friend add_pointer_t<_ValueType>
|
||||
any_cast(any *) _NOEXCEPT;
|
||||
|
||||
_HandleFuncPtr __h = nullptr;
|
||||
_Storage __s;
|
||||
_HandleFuncPtr __h_ = nullptr;
|
||||
_Storage __s_;
|
||||
};
|
||||
|
||||
namespace __any_imp
|
||||
|
@ -363,34 +388,42 @@ namespace __any_imp
|
|||
case _Action::_TypeInfo:
|
||||
return __type_info();
|
||||
}
|
||||
__libcpp_unreachable();
|
||||
}
|
||||
|
||||
template <class ..._Args>
|
||||
_LIBCPP_INLINE_VISIBILITY
|
||||
static _Tp& __create(any & __dest, _Args&&... __args) {
|
||||
_Tp* __ret = ::new (static_cast<void*>(&__dest.__s.__buf)) _Tp(_VSTD::forward<_Args>(__args)...);
|
||||
__dest.__h = &_SmallHandler::__handle;
|
||||
typedef allocator<_Tp> _Alloc;
|
||||
typedef allocator_traits<_Alloc> _ATraits;
|
||||
_Alloc __a;
|
||||
_Tp * __ret = static_cast<_Tp*>(static_cast<void*>(&__dest.__s_.__buf));
|
||||
_ATraits::construct(__a, __ret, _VSTD::forward<_Args>(__args)...);
|
||||
__dest.__h_ = &_SmallHandler::__handle;
|
||||
return *__ret;
|
||||
}
|
||||
|
||||
private:
|
||||
_LIBCPP_INLINE_VISIBILITY
|
||||
static void __destroy(any & __this) {
|
||||
_Tp & __value = *static_cast<_Tp *>(static_cast<void*>(&__this.__s.__buf));
|
||||
__value.~_Tp();
|
||||
__this.__h = nullptr;
|
||||
typedef allocator<_Tp> _Alloc;
|
||||
typedef allocator_traits<_Alloc> _ATraits;
|
||||
_Alloc __a;
|
||||
_Tp * __p = static_cast<_Tp *>(static_cast<void*>(&__this.__s_.__buf));
|
||||
_ATraits::destroy(__a, __p);
|
||||
__this.__h_ = nullptr;
|
||||
}
|
||||
|
||||
_LIBCPP_INLINE_VISIBILITY
|
||||
static void __copy(any const & __this, any & __dest) {
|
||||
_SmallHandler::__create(__dest, *static_cast<_Tp const *>(
|
||||
static_cast<void const *>(&__this.__s.__buf)));
|
||||
static_cast<void const *>(&__this.__s_.__buf)));
|
||||
}
|
||||
|
||||
_LIBCPP_INLINE_VISIBILITY
|
||||
static void __move(any & __this, any & __dest) {
|
||||
_SmallHandler::__create(__dest, _VSTD::move(
|
||||
*static_cast<_Tp*>(static_cast<void*>(&__this.__s.__buf))));
|
||||
*static_cast<_Tp*>(static_cast<void*>(&__this.__s_.__buf))));
|
||||
__destroy(__this);
|
||||
}
|
||||
|
||||
|
@ -400,14 +433,14 @@ namespace __any_imp
|
|||
const void* __fallback_id)
|
||||
{
|
||||
if (__any_imp::__compare_typeid<_Tp>(__info, __fallback_id))
|
||||
return static_cast<void*>(&__this.__s.__buf);
|
||||
return static_cast<void*>(&__this.__s_.__buf);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
_LIBCPP_INLINE_VISIBILITY
|
||||
static void* __type_info()
|
||||
{
|
||||
#if !defined(_LIBCPP_NO_RTTI)
|
||||
#if !defined(_LIBCPP_HAS_NO_RTTI)
|
||||
return const_cast<void*>(static_cast<void const *>(&typeid(_Tp)));
|
||||
#else
|
||||
return nullptr;
|
||||
|
@ -439,18 +472,21 @@ namespace __any_imp
|
|||
case _Action::_TypeInfo:
|
||||
return __type_info();
|
||||
}
|
||||
__libcpp_unreachable();
|
||||
}
|
||||
|
||||
template <class ..._Args>
|
||||
_LIBCPP_INLINE_VISIBILITY
|
||||
static _Tp& __create(any & __dest, _Args&&... __args) {
|
||||
typedef allocator<_Tp> _Alloc;
|
||||
typedef allocator_traits<_Alloc> _ATraits;
|
||||
typedef __allocator_destructor<_Alloc> _Dp;
|
||||
_Alloc __a;
|
||||
unique_ptr<_Tp, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
|
||||
_Tp* __ret = ::new ((void*)__hold.get()) _Tp(_VSTD::forward<_Args>(__args)...);
|
||||
__dest.__s.__ptr = __hold.release();
|
||||
__dest.__h = &_LargeHandler::__handle;
|
||||
unique_ptr<_Tp, _Dp> __hold(_ATraits::allocate(__a, 1), _Dp(__a, 1));
|
||||
_Tp * __ret = __hold.get();
|
||||
_ATraits::construct(__a, __ret, _VSTD::forward<_Args>(__args)...);
|
||||
__dest.__s_.__ptr = __hold.release();
|
||||
__dest.__h_ = &_LargeHandler::__handle;
|
||||
return *__ret;
|
||||
}
|
||||
|
||||
|
@ -458,20 +494,25 @@ namespace __any_imp
|
|||
|
||||
_LIBCPP_INLINE_VISIBILITY
|
||||
static void __destroy(any & __this){
|
||||
delete static_cast<_Tp*>(__this.__s.__ptr);
|
||||
__this.__h = nullptr;
|
||||
typedef allocator<_Tp> _Alloc;
|
||||
typedef allocator_traits<_Alloc> _ATraits;
|
||||
_Alloc __a;
|
||||
_Tp * __p = static_cast<_Tp *>(__this.__s_.__ptr);
|
||||
_ATraits::destroy(__a, __p);
|
||||
_ATraits::deallocate(__a, __p, 1);
|
||||
__this.__h_ = nullptr;
|
||||
}
|
||||
|
||||
_LIBCPP_INLINE_VISIBILITY
|
||||
static void __copy(any const & __this, any & __dest) {
|
||||
_LargeHandler::__create(__dest, *static_cast<_Tp const *>(__this.__s.__ptr));
|
||||
_LargeHandler::__create(__dest, *static_cast<_Tp const *>(__this.__s_.__ptr));
|
||||
}
|
||||
|
||||
_LIBCPP_INLINE_VISIBILITY
|
||||
static void __move(any & __this, any & __dest) {
|
||||
__dest.__s.__ptr = __this.__s.__ptr;
|
||||
__dest.__h = &_LargeHandler::__handle;
|
||||
__this.__h = nullptr;
|
||||
__dest.__s_.__ptr = __this.__s_.__ptr;
|
||||
__dest.__h_ = &_LargeHandler::__handle;
|
||||
__this.__h_ = nullptr;
|
||||
}
|
||||
|
||||
_LIBCPP_INLINE_VISIBILITY
|
||||
|
@ -479,7 +520,7 @@ namespace __any_imp
|
|||
void const* __fallback_info)
|
||||
{
|
||||
if (__any_imp::__compare_typeid<_Tp>(__info, __fallback_info))
|
||||
return static_cast<void*>(__this.__s.__ptr);
|
||||
return static_cast<void*>(__this.__s_.__ptr);
|
||||
return nullptr;
|
||||
|
||||
}
|
||||
|
@ -487,7 +528,7 @@ namespace __any_imp
|
|||
_LIBCPP_INLINE_VISIBILITY
|
||||
static void* __type_info()
|
||||
{
|
||||
#if !defined(_LIBCPP_NO_RTTI)
|
||||
#if !defined(_LIBCPP_HAS_NO_RTTI)
|
||||
return const_cast<void*>(static_cast<void const *>(&typeid(_Tp)));
|
||||
#else
|
||||
return nullptr;
|
||||
|
@ -499,7 +540,7 @@ namespace __any_imp
|
|||
|
||||
|
||||
template <class _ValueType, class _Tp, class>
|
||||
any::any(_ValueType && __v) : __h(nullptr)
|
||||
any::any(_ValueType && __v) : __h_(nullptr)
|
||||
{
|
||||
__any_imp::_Handler<_Tp>::__create(*this, _VSTD::forward<_ValueType>(__v));
|
||||
}
|
||||
|
@ -541,16 +582,16 @@ void any::swap(any & __rhs) _NOEXCEPT
|
|||
{
|
||||
if (this == &__rhs)
|
||||
return;
|
||||
if (__h && __rhs.__h) {
|
||||
if (__h_ && __rhs.__h_) {
|
||||
any __tmp;
|
||||
__rhs.__call(_Action::_Move, &__tmp);
|
||||
this->__call(_Action::_Move, &__rhs);
|
||||
__tmp.__call(_Action::_Move, this);
|
||||
}
|
||||
else if (__h) {
|
||||
else if (__h_) {
|
||||
this->__call(_Action::_Move, &__rhs);
|
||||
}
|
||||
else if (__rhs.__h) {
|
||||
else if (__rhs.__h_) {
|
||||
__rhs.__call(_Action::_Move, this);
|
||||
}
|
||||
}
|
||||
|
@ -580,7 +621,7 @@ inline _LIBCPP_INLINE_VISIBILITY
|
|||
_LIBCPP_AVAILABILITY_THROW_BAD_ANY_CAST
|
||||
_ValueType any_cast(any const & __v)
|
||||
{
|
||||
using _RawValueType = __uncvref_t<_ValueType>;
|
||||
using _RawValueType = __remove_cvref_t<_ValueType>;
|
||||
static_assert(is_constructible<_ValueType, _RawValueType const &>::value,
|
||||
"ValueType is required to be a const lvalue reference "
|
||||
"or a CopyConstructible type");
|
||||
|
@ -595,7 +636,7 @@ inline _LIBCPP_INLINE_VISIBILITY
|
|||
_LIBCPP_AVAILABILITY_THROW_BAD_ANY_CAST
|
||||
_ValueType any_cast(any & __v)
|
||||
{
|
||||
using _RawValueType = __uncvref_t<_ValueType>;
|
||||
using _RawValueType = __remove_cvref_t<_ValueType>;
|
||||
static_assert(is_constructible<_ValueType, _RawValueType &>::value,
|
||||
"ValueType is required to be an lvalue reference "
|
||||
"or a CopyConstructible type");
|
||||
|
@ -610,7 +651,7 @@ inline _LIBCPP_INLINE_VISIBILITY
|
|||
_LIBCPP_AVAILABILITY_THROW_BAD_ANY_CAST
|
||||
_ValueType any_cast(any && __v)
|
||||
{
|
||||
using _RawValueType = __uncvref_t<_ValueType>;
|
||||
using _RawValueType = __remove_cvref_t<_ValueType>;
|
||||
static_assert(is_constructible<_ValueType, _RawValueType>::value,
|
||||
"ValueType is required to be an rvalue reference "
|
||||
"or a CopyConstructible type");
|
||||
|
@ -643,16 +684,17 @@ _RetType __pointer_or_func_cast(void*, /*IsFunction*/true_type) noexcept {
|
|||
}
|
||||
|
||||
template <class _ValueType>
|
||||
_LIBCPP_HIDE_FROM_ABI
|
||||
add_pointer_t<_ValueType>
|
||||
any_cast(any * __any) _NOEXCEPT
|
||||
{
|
||||
using __any_imp::_Action;
|
||||
static_assert(!is_reference<_ValueType>::value,
|
||||
"_ValueType may not be a reference.");
|
||||
typedef typename add_pointer<_ValueType>::type _ReturnType;
|
||||
if (__any && __any->__h) {
|
||||
typedef add_pointer_t<_ValueType> _ReturnType;
|
||||
if (__any && __any->__h_) {
|
||||
void *__p = __any->__call(_Action::_Get, nullptr,
|
||||
#if !defined(_LIBCPP_NO_RTTI)
|
||||
#if !defined(_LIBCPP_HAS_NO_RTTI)
|
||||
&typeid(_ValueType),
|
||||
#else
|
||||
nullptr,
|
||||
|
@ -664,8 +706,24 @@ any_cast(any * __any) _NOEXCEPT
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
#endif // _LIBCPP_STD_VER > 14
|
||||
#endif // _LIBCPP_STD_VER >= 17
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
||||
#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 17
|
||||
# include <chrono>
|
||||
#endif
|
||||
|
||||
#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
|
||||
# include <atomic>
|
||||
# include <concepts>
|
||||
# include <cstdlib>
|
||||
# include <iosfwd>
|
||||
# include <iterator>
|
||||
# include <memory>
|
||||
# include <stdexcept>
|
||||
# include <type_traits>
|
||||
# include <variant>
|
||||
#endif
|
||||
|
||||
#endif // _LIBCPP_ANY
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue