diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2025-04-05 01:46:13 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-04-05 01:46:13 -0400 |
| commit | 0cd31fc7ff157551cfbba5da35cd79f118d2a2e3 (patch) | |
| tree | a308488f5d85184c8ec402fb3f55f1cf2704443e /lib/libcxx/include/__utility | |
| parent | 8acedfd5baabab705946ad097746f9183ef62420 (diff) | |
| parent | cefe65c1b8abe65a22d4b68410db1be264fdeda0 (diff) | |
| download | zig-0cd31fc7ff157551cfbba5da35cd79f118d2a2e3.tar.gz zig-0cd31fc7ff157551cfbba5da35cd79f118d2a2e3.zip | |
Merge pull request #22780 from ziglang/llvm20
LLVM 20
Diffstat (limited to 'lib/libcxx/include/__utility')
| -rw-r--r-- | lib/libcxx/include/__utility/as_const.h | 5 | ||||
| -rw-r--r-- | lib/libcxx/include/__utility/convert_to_integral.h | 2 | ||||
| -rw-r--r-- | lib/libcxx/include/__utility/element_count.h | 27 | ||||
| -rw-r--r-- | lib/libcxx/include/__utility/exception_guard.h | 18 | ||||
| -rw-r--r-- | lib/libcxx/include/__utility/forward.h | 4 | ||||
| -rw-r--r-- | lib/libcxx/include/__utility/forward_like.h | 23 | ||||
| -rw-r--r-- | lib/libcxx/include/__utility/in_place.h | 7 | ||||
| -rw-r--r-- | lib/libcxx/include/__utility/integer_sequence.h | 10 | ||||
| -rw-r--r-- | lib/libcxx/include/__utility/is_pointer_in_range.h | 8 | ||||
| -rw-r--r-- | lib/libcxx/include/__utility/move.h | 8 | ||||
| -rw-r--r-- | lib/libcxx/include/__utility/no_destroy.h | 2 | ||||
| -rw-r--r-- | lib/libcxx/include/__utility/pair.h | 62 | ||||
| -rw-r--r-- | lib/libcxx/include/__utility/priority_tag.h | 2 | ||||
| -rw-r--r-- | lib/libcxx/include/__utility/scope_guard.h | 56 | ||||
| -rw-r--r-- | lib/libcxx/include/__utility/small_buffer.h | 10 | ||||
| -rw-r--r-- | lib/libcxx/include/__utility/swap.h | 8 | ||||
| -rw-r--r-- | lib/libcxx/include/__utility/unreachable.h | 2 |
17 files changed, 162 insertions, 92 deletions
diff --git a/lib/libcxx/include/__utility/as_const.h b/lib/libcxx/include/__utility/as_const.h index 582dd42f40..0f54b98472 100644 --- a/lib/libcxx/include/__utility/as_const.h +++ b/lib/libcxx/include/__utility/as_const.h @@ -10,9 +10,6 @@ #define _LIBCPP___UTILITY_AS_CONST_H #include <__config> -#include <__type_traits/add_const.h> -#include <__utility/forward.h> -#include <__utility/move.h> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header @@ -22,7 +19,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD #if _LIBCPP_STD_VER >= 17 template <class _Tp> -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr add_const_t<_Tp>& as_const(_Tp& __t) noexcept { +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr const _Tp& as_const(_Tp& __t) noexcept { return __t; } diff --git a/lib/libcxx/include/__utility/convert_to_integral.h b/lib/libcxx/include/__utility/convert_to_integral.h index f1fcdd9801..8947c349d8 100644 --- a/lib/libcxx/include/__utility/convert_to_integral.h +++ b/lib/libcxx/include/__utility/convert_to_integral.h @@ -42,7 +42,7 @@ inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR long long __convert_to_integral(_ return __val; } -#ifndef _LIBCPP_HAS_NO_INT128 +#if _LIBCPP_HAS_INT128 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR __int128_t __convert_to_integral(__int128_t __val) { return __val; } inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR __uint128_t __convert_to_integral(__uint128_t __val) { return __val; } diff --git a/lib/libcxx/include/__utility/element_count.h b/lib/libcxx/include/__utility/element_count.h new file mode 100644 index 0000000000..82b05a7bde --- /dev/null +++ b/lib/libcxx/include/__utility/element_count.h @@ -0,0 +1,27 @@ +//===----------------------------------------------------------------------===// +// +// 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 +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP___UTILITY_ELEMENT_COUNT_H +#define _LIBCPP___UTILITY_ELEMENT_COUNT_H + +#include <__config> +#include <__cstddef/size_t.h> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +// Type used to encode that a function takes an integer that represents a number +// of elements as opposed to a number of bytes. +enum class __element_count : size_t {}; + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP___UTILITY_ELEMENT_COUNT_H diff --git a/lib/libcxx/include/__utility/exception_guard.h b/lib/libcxx/include/__utility/exception_guard.h index 9f732ca265..a6b4ec5211 100644 --- a/lib/libcxx/include/__utility/exception_guard.h +++ b/lib/libcxx/include/__utility/exception_guard.h @@ -44,7 +44,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD // less common, especially one that tries to catch an exception through -fno-exceptions code. // // __exception_guard can help greatly simplify code that would normally be cluttered by -// `#if _LIBCPP_HAS_NO_EXCEPTIONS`. For example: +// `#if _LIBCPP_HAS_EXCEPTIONS`. For example: // // template <class Iterator, class Size, class OutputIterator> // Iterator uninitialized_copy_n(Iterator iter, Size n, OutputIterator out) { @@ -96,10 +96,10 @@ _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(__exception_guard_exceptions); template <class _Rollback> struct __exception_guard_noexceptions { __exception_guard_noexceptions() = delete; - _LIBCPP_HIDE_FROM_ABI - _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_NODEBUG explicit __exception_guard_noexceptions(_Rollback) {} + _LIBCPP_NODEBUG _LIBCPP_HIDE_FROM_ABI + _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit __exception_guard_noexceptions(_Rollback) {} - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_NODEBUG + _LIBCPP_NODEBUG _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __exception_guard_noexceptions(__exception_guard_noexceptions&& __other) _NOEXCEPT_(is_nothrow_move_constructible<_Rollback>::value) : __completed_(__other.__completed_) { @@ -110,11 +110,11 @@ struct __exception_guard_noexceptions { __exception_guard_noexceptions& operator=(__exception_guard_noexceptions const&) = delete; __exception_guard_noexceptions& operator=(__exception_guard_noexceptions&&) = delete; - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_NODEBUG void __complete() _NOEXCEPT { + _LIBCPP_NODEBUG _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __complete() _NOEXCEPT { __completed_ = true; } - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_NODEBUG ~__exception_guard_noexceptions() { + _LIBCPP_NODEBUG _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 ~__exception_guard_noexceptions() { _LIBCPP_ASSERT_INTERNAL(__completed_, "__exception_guard not completed with exceptions disabled"); } @@ -124,12 +124,12 @@ private: _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(__exception_guard_noexceptions); -#ifdef _LIBCPP_HAS_NO_EXCEPTIONS +#if !_LIBCPP_HAS_EXCEPTIONS template <class _Rollback> -using __exception_guard = __exception_guard_noexceptions<_Rollback>; +using __exception_guard _LIBCPP_NODEBUG = __exception_guard_noexceptions<_Rollback>; #else template <class _Rollback> -using __exception_guard = __exception_guard_exceptions<_Rollback>; +using __exception_guard _LIBCPP_NODEBUG = __exception_guard_exceptions<_Rollback>; #endif template <class _Rollback> diff --git a/lib/libcxx/include/__utility/forward.h b/lib/libcxx/include/__utility/forward.h index d5275dcbd0..6674066447 100644 --- a/lib/libcxx/include/__utility/forward.h +++ b/lib/libcxx/include/__utility/forward.h @@ -21,13 +21,13 @@ _LIBCPP_BEGIN_NAMESPACE_STD template <class _Tp> -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _Tp&& +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _Tp&& forward(_LIBCPP_LIFETIMEBOUND __libcpp_remove_reference_t<_Tp>& __t) _NOEXCEPT { return static_cast<_Tp&&>(__t); } template <class _Tp> -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _Tp&& +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _Tp&& forward(_LIBCPP_LIFETIMEBOUND __libcpp_remove_reference_t<_Tp>&& __t) _NOEXCEPT { static_assert(!is_lvalue_reference<_Tp>::value, "cannot forward an rvalue as an lvalue"); return static_cast<_Tp&&>(__t); diff --git a/lib/libcxx/include/__utility/forward_like.h b/lib/libcxx/include/__utility/forward_like.h index 0206ce23a5..409f716cfb 100644 --- a/lib/libcxx/include/__utility/forward_like.h +++ b/lib/libcxx/include/__utility/forward_like.h @@ -12,6 +12,7 @@ #include <__config> #include <__type_traits/conditional.h> +#include <__type_traits/is_base_of.h> #include <__type_traits/is_const.h> #include <__type_traits/is_reference.h> #include <__type_traits/remove_reference.h> @@ -25,13 +26,13 @@ _LIBCPP_BEGIN_NAMESPACE_STD #if _LIBCPP_STD_VER >= 23 template <class _Ap, class _Bp> -using _CopyConst = _If<is_const_v<_Ap>, const _Bp, _Bp>; +using _CopyConst _LIBCPP_NODEBUG = _If<is_const_v<_Ap>, const _Bp, _Bp>; template <class _Ap, class _Bp> -using _OverrideRef = _If<is_rvalue_reference_v<_Ap>, remove_reference_t<_Bp>&&, _Bp&>; +using _OverrideRef _LIBCPP_NODEBUG = _If<is_rvalue_reference_v<_Ap>, remove_reference_t<_Bp>&&, _Bp&>; template <class _Ap, class _Bp> -using _ForwardLike = _OverrideRef<_Ap&&, _CopyConst<remove_reference_t<_Ap>, remove_reference_t<_Bp>>>; +using _ForwardLike _LIBCPP_NODEBUG = _OverrideRef<_Ap&&, _CopyConst<remove_reference_t<_Ap>, remove_reference_t<_Bp>>>; template <class _Tp, class _Up> [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto @@ -39,6 +40,22 @@ forward_like(_LIBCPP_LIFETIMEBOUND _Up&& __ux) noexcept -> _ForwardLike<_Tp, _Up return static_cast<_ForwardLike<_Tp, _Up>>(__ux); } +// This function is used for `deducing this` cases where you want to make sure the operation is performed on the class +// itself and not on a derived class. For example +// struct S { +// template <class Self> +// void func(Self&& self) { +// // This will always call `do_something` of S instead of any class derived from S. +// std::__forward_as<Self, S>(self).do_something(); +// } +// }; +template <class _Tp, class _As, class _Up> +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _ForwardLike<_Tp, _As> +__forward_as(_LIBCPP_LIFETIMEBOUND _Up&& __val) noexcept { + static_assert(is_base_of_v<_As, remove_reference_t<_Up>>); + return static_cast<_ForwardLike<_Tp, _As>>(__val); +} + #endif // _LIBCPP_STD_VER >= 23 _LIBCPP_END_NAMESPACE_STD diff --git a/lib/libcxx/include/__utility/in_place.h b/lib/libcxx/include/__utility/in_place.h index fa7a2f4bfd..9b48446d83 100644 --- a/lib/libcxx/include/__utility/in_place.h +++ b/lib/libcxx/include/__utility/in_place.h @@ -10,8 +10,9 @@ #define _LIBCPP___UTILITY_IN_PLACE_H #include <__config> +#include <__cstddef/size_t.h> +#include <__type_traits/integral_constant.h> #include <__type_traits/remove_cvref.h> -#include <cstddef> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header @@ -46,7 +47,7 @@ template <class _Tp> struct __is_inplace_type_imp<in_place_type_t<_Tp>> : true_type {}; template <class _Tp> -using __is_inplace_type = __is_inplace_type_imp<__remove_cvref_t<_Tp>>; +using __is_inplace_type _LIBCPP_NODEBUG = __is_inplace_type_imp<__remove_cvref_t<_Tp>>; template <class _Tp> struct __is_inplace_index_imp : false_type {}; @@ -54,7 +55,7 @@ template <size_t _Idx> struct __is_inplace_index_imp<in_place_index_t<_Idx>> : true_type {}; template <class _Tp> -using __is_inplace_index = __is_inplace_index_imp<__remove_cvref_t<_Tp>>; +using __is_inplace_index _LIBCPP_NODEBUG = __is_inplace_index_imp<__remove_cvref_t<_Tp>>; #endif // _LIBCPP_STD_VER >= 17 diff --git a/lib/libcxx/include/__utility/integer_sequence.h b/lib/libcxx/include/__utility/integer_sequence.h index ccce9433e7..2c1ff3c543 100644 --- a/lib/libcxx/include/__utility/integer_sequence.h +++ b/lib/libcxx/include/__utility/integer_sequence.h @@ -10,8 +10,8 @@ #define _LIBCPP___UTILITY_INTEGER_SEQUENCE_H #include <__config> +#include <__cstddef/size_t.h> #include <__type_traits/is_integral.h> -#include <cstddef> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header @@ -25,19 +25,19 @@ struct __tuple_indices; template <class _IdxType, _IdxType... _Values> struct __integer_sequence { template <template <class _OIdxType, _OIdxType...> class _ToIndexSeq, class _ToIndexType> - using __convert = _ToIndexSeq<_ToIndexType, _Values...>; + using __convert _LIBCPP_NODEBUG = _ToIndexSeq<_ToIndexType, _Values...>; template <size_t _Sp> - using __to_tuple_indices = __tuple_indices<(_Values + _Sp)...>; + using __to_tuple_indices _LIBCPP_NODEBUG = __tuple_indices<(_Values + _Sp)...>; }; #if __has_builtin(__make_integer_seq) template <size_t _Ep, size_t _Sp> -using __make_indices_imp = +using __make_indices_imp _LIBCPP_NODEBUG = typename __make_integer_seq<__integer_sequence, size_t, _Ep - _Sp>::template __to_tuple_indices<_Sp>; #elif __has_builtin(__integer_pack) template <size_t _Ep, size_t _Sp> -using __make_indices_imp = +using __make_indices_imp _LIBCPP_NODEBUG = typename __integer_sequence<size_t, __integer_pack(_Ep - _Sp)...>::template __to_tuple_indices<_Sp>; #else # error "No known way to get an integer pack from the compiler" diff --git a/lib/libcxx/include/__utility/is_pointer_in_range.h b/lib/libcxx/include/__utility/is_pointer_in_range.h index 4130b4ac70..55fac6256b 100644 --- a/lib/libcxx/include/__utility/is_pointer_in_range.h +++ b/lib/libcxx/include/__utility/is_pointer_in_range.h @@ -57,6 +57,14 @@ __is_pointer_in_range(const _Tp* __begin, const _Tp* __end, const _Up* __ptr) { reinterpret_cast<const char*>(__ptr) < reinterpret_cast<const char*>(__end); } +template <class _Tp, class _Up> +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool +__is_overlapping_range(const _Tp* __begin, const _Tp* __end, const _Up* __begin2) { + auto __size = __end - __begin; + auto __end2 = __begin2 + __size; + return std::__is_pointer_in_range(__begin, __end, __begin2) || std::__is_pointer_in_range(__begin2, __end2, __begin); +} + _LIBCPP_END_NAMESPACE_STD #endif // _LIBCPP___UTILITY_IS_POINTER_IN_RANGE_H diff --git a/lib/libcxx/include/__utility/move.h b/lib/libcxx/include/__utility/move.h index b6a42db054..bc16697b5c 100644 --- a/lib/libcxx/include/__utility/move.h +++ b/lib/libcxx/include/__utility/move.h @@ -26,18 +26,18 @@ _LIBCPP_PUSH_MACROS _LIBCPP_BEGIN_NAMESPACE_STD template <class _Tp> -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR __libcpp_remove_reference_t<_Tp>&& +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR __libcpp_remove_reference_t<_Tp>&& move(_LIBCPP_LIFETIMEBOUND _Tp&& __t) _NOEXCEPT { - typedef _LIBCPP_NODEBUG __libcpp_remove_reference_t<_Tp> _Up; + using _Up _LIBCPP_NODEBUG = __libcpp_remove_reference_t<_Tp>; return static_cast<_Up&&>(__t); } template <class _Tp> -using __move_if_noexcept_result_t = +using __move_if_noexcept_result_t _LIBCPP_NODEBUG = __conditional_t<!is_nothrow_move_constructible<_Tp>::value && is_copy_constructible<_Tp>::value, const _Tp&, _Tp&&>; template <class _Tp> -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 __move_if_noexcept_result_t<_Tp> +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 __move_if_noexcept_result_t<_Tp> move_if_noexcept(_LIBCPP_LIFETIMEBOUND _Tp& __x) _NOEXCEPT { return std::move(__x); } diff --git a/lib/libcxx/include/__utility/no_destroy.h b/lib/libcxx/include/__utility/no_destroy.h index 8edd194577..16f424ae11 100644 --- a/lib/libcxx/include/__utility/no_destroy.h +++ b/lib/libcxx/include/__utility/no_destroy.h @@ -10,9 +10,9 @@ #define _LIBCPP___UTILITY_NO_DESTROY_H #include <__config> +#include <__new/placement_new_delete.h> #include <__type_traits/is_constant_evaluated.h> #include <__utility/forward.h> -#include <new> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header diff --git a/lib/libcxx/include/__utility/pair.h b/lib/libcxx/include/__utility/pair.h index c0002b7abb..7689ab2a48 100644 --- a/lib/libcxx/include/__utility/pair.h +++ b/lib/libcxx/include/__utility/pair.h @@ -13,11 +13,10 @@ #include <__compare/synth_three_way.h> #include <__concepts/different_from.h> #include <__config> +#include <__cstddef/size_t.h> #include <__fwd/array.h> #include <__fwd/pair.h> #include <__fwd/tuple.h> -#include <__tuple/sfinae_helpers.h> -#include <__tuple/tuple_element.h> #include <__tuple/tuple_indices.h> #include <__tuple/tuple_like_no_subrange.h> #include <__tuple/tuple_size.h> @@ -25,6 +24,7 @@ #include <__type_traits/common_type.h> #include <__type_traits/conditional.h> #include <__type_traits/decay.h> +#include <__type_traits/enable_if.h> #include <__type_traits/integral_constant.h> #include <__type_traits/is_assignable.h> #include <__type_traits/is_constructible.h> @@ -32,7 +32,6 @@ #include <__type_traits/is_implicitly_default_constructible.h> #include <__type_traits/is_nothrow_assignable.h> #include <__type_traits/is_nothrow_constructible.h> -#include <__type_traits/is_reference.h> #include <__type_traits/is_same.h> #include <__type_traits/is_swappable.h> #include <__type_traits/is_trivially_relocatable.h> @@ -43,7 +42,6 @@ #include <__utility/forward.h> #include <__utility/move.h> #include <__utility/piecewise_construct.h> -#include <cstddef> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header @@ -73,7 +71,7 @@ struct _LIBCPP_TEMPLATE_VIS pair _T1 first; _T2 second; - using __trivially_relocatable = + using __trivially_relocatable _LIBCPP_NODEBUG = __conditional_t<__libcpp_is_trivially_relocatable<_T1>::value && __libcpp_is_trivially_relocatable<_T2>::value, pair, void>; @@ -81,38 +79,6 @@ struct _LIBCPP_TEMPLATE_VIS pair _LIBCPP_HIDE_FROM_ABI pair(pair const&) = default; _LIBCPP_HIDE_FROM_ABI pair(pair&&) = default; - // When we are requested for pair to be trivially copyable by the ABI macro, we use defaulted members - // if it is both legal to do it (i.e. no references) and we have a way to actually implement it, which requires - // the __enable_if__ attribute before C++20. -#ifdef _LIBCPP_ABI_TRIVIALLY_COPYABLE_PAIR - // FIXME: This should really just be a static constexpr variable. It's in a struct to avoid gdb printing the value - // when printing a pair - struct __has_defaulted_members { - static const bool value = !is_reference<first_type>::value && !is_reference<second_type>::value; - }; -# if _LIBCPP_STD_VER >= 20 - _LIBCPP_HIDE_FROM_ABI constexpr pair& operator=(const pair&) - requires __has_defaulted_members::value - = default; - - _LIBCPP_HIDE_FROM_ABI constexpr pair& operator=(pair&&) - requires __has_defaulted_members::value - = default; -# elif __has_attribute(__enable_if__) - _LIBCPP_HIDE_FROM_ABI pair& operator=(const pair&) - __attribute__((__enable_if__(__has_defaulted_members::value, ""))) = default; - - _LIBCPP_HIDE_FROM_ABI pair& operator=(pair&&) - __attribute__((__enable_if__(__has_defaulted_members::value, ""))) = default; -# else -# error "_LIBCPP_ABI_TRIVIALLY_COPYABLE_PAIR isn't supported with this compiler" -# endif -#else - struct __has_defaulted_members { - static const bool value = false; - }; -#endif // defined(_LIBCPP_ABI_TRIVIALLY_COPYABLE_PAIR) && __has_attribute(__enable_if__) - #ifdef _LIBCPP_CXX03_LANG _LIBCPP_HIDE_FROM_ABI pair() : first(), second() {} @@ -164,8 +130,7 @@ struct _LIBCPP_TEMPLATE_VIS pair }; template <bool _MaybeEnable> - using _CheckArgsDep _LIBCPP_NODEBUG = - typename conditional< _MaybeEnable, _CheckArgs, __check_tuple_constructor_fail>::type; + using _CheckArgsDep _LIBCPP_NODEBUG = __conditional_t<_MaybeEnable, _CheckArgs, void>; template <bool _Dummy = true, __enable_if_t<_CheckArgsDep<_Dummy>::__enable_default(), int> = 0> explicit(!_CheckArgsDep<_Dummy>::__enable_implicit_default()) _LIBCPP_HIDE_FROM_ABI constexpr pair() noexcept( @@ -258,8 +223,7 @@ struct _LIBCPP_TEMPLATE_VIS pair typename __make_tuple_indices<sizeof...(_Args2) >::type()) {} _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair& - operator=(__conditional_t<!__has_defaulted_members::value && is_copy_assignable<first_type>::value && - is_copy_assignable<second_type>::value, + operator=(__conditional_t<is_copy_assignable<first_type>::value && is_copy_assignable<second_type>::value, pair, __nat> const& __p) noexcept(is_nothrow_copy_assignable<first_type>::value && is_nothrow_copy_assignable<second_type>::value) { @@ -268,12 +232,10 @@ struct _LIBCPP_TEMPLATE_VIS pair return *this; } - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair& - operator=(__conditional_t<!__has_defaulted_members::value && is_move_assignable<first_type>::value && - is_move_assignable<second_type>::value, - pair, - __nat>&& __p) noexcept(is_nothrow_move_assignable<first_type>::value && - is_nothrow_move_assignable<second_type>::value) { + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair& operator=( + __conditional_t<is_move_assignable<first_type>::value && is_move_assignable<second_type>::value, pair, __nat>&& + __p) noexcept(is_nothrow_move_assignable<first_type>::value && + is_nothrow_move_assignable<second_type>::value) { first = std::forward<first_type>(__p.first); second = std::forward<second_type>(__p.second); return *this; @@ -570,11 +532,9 @@ swap(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y) noexcept(noexcept(__x #endif template <class _T1, class _T2> -inline _LIBCPP_HIDE_FROM_ABI -_LIBCPP_CONSTEXPR_SINCE_CXX14 pair<typename __unwrap_ref_decay<_T1>::type, typename __unwrap_ref_decay<_T2>::type> +inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<__unwrap_ref_decay_t<_T1>, __unwrap_ref_decay_t<_T2> > make_pair(_T1&& __t1, _T2&& __t2) { - return pair<typename __unwrap_ref_decay<_T1>::type, typename __unwrap_ref_decay<_T2>::type>( - std::forward<_T1>(__t1), std::forward<_T2>(__t2)); + return pair<__unwrap_ref_decay_t<_T1>, __unwrap_ref_decay_t<_T2> >(std::forward<_T1>(__t1), std::forward<_T2>(__t2)); } template <class _T1, class _T2> diff --git a/lib/libcxx/include/__utility/priority_tag.h b/lib/libcxx/include/__utility/priority_tag.h index a159ce7f1a..ef7cf162b9 100644 --- a/lib/libcxx/include/__utility/priority_tag.h +++ b/lib/libcxx/include/__utility/priority_tag.h @@ -10,7 +10,7 @@ #define _LIBCPP___UTILITY_PRIORITY_TAG_H #include <__config> -#include <cstddef> +#include <__cstddef/size_t.h> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header diff --git a/lib/libcxx/include/__utility/scope_guard.h b/lib/libcxx/include/__utility/scope_guard.h new file mode 100644 index 0000000000..e51b300d1f --- /dev/null +++ b/lib/libcxx/include/__utility/scope_guard.h @@ -0,0 +1,56 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// 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 +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP___UTILITY_SCOPE_GUARD_H +#define _LIBCPP___UTILITY_SCOPE_GUARD_H + +#include <__assert> +#include <__config> +#include <__utility/move.h> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + +_LIBCPP_BEGIN_NAMESPACE_STD + +template <class _Func> +class __scope_guard { + _Func __func_; + +public: + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR explicit __scope_guard(_Func __func) : __func_(std::move(__func)) {} + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 ~__scope_guard() { __func_(); } + + __scope_guard(const __scope_guard&) = delete; + __scope_guard& operator=(const __scope_guard&) = delete; + __scope_guard& operator=(__scope_guard&&) = delete; + +// C++14 doesn't have mandatory RVO, so we have to provide a declaration even though no compiler will ever generate +// a call to the move constructor. +#if _LIBCPP_STD_VER <= 14 + __scope_guard(__scope_guard&&); +#else + __scope_guard(__scope_guard&&) = delete; +#endif +}; + +template <class _Func> +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 __scope_guard<_Func> __make_scope_guard(_Func __func) { + return __scope_guard<_Func>(std::move(__func)); +} + +_LIBCPP_END_NAMESPACE_STD + +_LIBCPP_POP_MACROS + +#endif // _LIBCPP___UTILITY_SCOPE_GUARD_H diff --git a/lib/libcxx/include/__utility/small_buffer.h b/lib/libcxx/include/__utility/small_buffer.h index 9e13797573..132a57f0fe 100644 --- a/lib/libcxx/include/__utility/small_buffer.h +++ b/lib/libcxx/include/__utility/small_buffer.h @@ -10,14 +10,16 @@ #define _LIBCPP___UTILITY_SMALL_BUFFER_H #include <__config> +#include <__cstddef/byte.h> +#include <__cstddef/size_t.h> #include <__memory/construct_at.h> +#include <__new/allocate.h> +#include <__new/launder.h> #include <__type_traits/decay.h> #include <__type_traits/is_trivially_constructible.h> #include <__type_traits/is_trivially_destructible.h> #include <__utility/exception_guard.h> #include <__utility/forward.h> -#include <cstddef> -#include <new> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header @@ -66,7 +68,7 @@ public: if constexpr (__fits_in_buffer<_Stored>) { return std::launder(reinterpret_cast<_Stored*>(__buffer_)); } else { - byte* __allocation = static_cast<byte*>(::operator new[](sizeof(_Stored), align_val_t{alignof(_Stored)})); + byte* __allocation = reinterpret_cast<byte*>(std::__libcpp_allocate<_Stored>(__element_count(1))); std::construct_at(reinterpret_cast<byte**>(__buffer_), __allocation); return std::launder(reinterpret_cast<_Stored*>(__allocation)); } @@ -75,7 +77,7 @@ public: template <class _Stored> _LIBCPP_HIDE_FROM_ABI void __dealloc() noexcept { if constexpr (!__fits_in_buffer<_Stored>) - ::operator delete[](*reinterpret_cast<void**>(__buffer_), sizeof(_Stored), align_val_t{alignof(_Stored)}); + std::__libcpp_deallocate<_Stored>(__get<_Stored>(), __element_count(1)); } template <class _Stored, class... _Args> diff --git a/lib/libcxx/include/__utility/swap.h b/lib/libcxx/include/__utility/swap.h index ab88b8e0a0..b4311540d3 100644 --- a/lib/libcxx/include/__utility/swap.h +++ b/lib/libcxx/include/__utility/swap.h @@ -10,6 +10,8 @@ #define _LIBCPP___UTILITY_SWAP_H #include <__config> +#include <__cstddef/size_t.h> +#include <__type_traits/enable_if.h> #include <__type_traits/is_assignable.h> #include <__type_traits/is_constructible.h> #include <__type_traits/is_nothrow_assignable.h> @@ -17,7 +19,6 @@ #include <__type_traits/is_swappable.h> #include <__utility/declval.h> #include <__utility/move.h> -#include <cstddef> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header @@ -30,10 +31,11 @@ _LIBCPP_BEGIN_NAMESPACE_STD #ifndef _LIBCPP_CXX03_LANG template <class _Tp> -using __swap_result_t = __enable_if_t<is_move_constructible<_Tp>::value && is_move_assignable<_Tp>::value>; +using __swap_result_t _LIBCPP_NODEBUG = + __enable_if_t<is_move_constructible<_Tp>::value && is_move_assignable<_Tp>::value>; #else template <class> -using __swap_result_t = void; +using __swap_result_t _LIBCPP_NODEBUG = void; #endif template <class _Tp> diff --git a/lib/libcxx/include/__utility/unreachable.h b/lib/libcxx/include/__utility/unreachable.h index d833f74c2e..5525452aa5 100644 --- a/lib/libcxx/include/__utility/unreachable.h +++ b/lib/libcxx/include/__utility/unreachable.h @@ -18,7 +18,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD -_LIBCPP_NORETURN _LIBCPP_HIDE_FROM_ABI inline void __libcpp_unreachable() { +[[__noreturn__]] _LIBCPP_HIDE_FROM_ABI inline void __libcpp_unreachable() { _LIBCPP_ASSERT_INTERNAL(false, "std::unreachable() was reached"); __builtin_unreachable(); } |
