Skip to content

[libc++] Put _LIBCPP_NODEBUG on allocator trait aliases. #118835

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 32 additions & 34 deletions libcxx/include/__memory/allocator_traits.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ _LIBCPP_BEGIN_NAMESPACE_STD

// __pointer
template <class _Tp>
using __pointer_member = typename _Tp::pointer;
using __pointer_member _LIBCPP_NODEBUG = typename _Tp::pointer;

template <class _Tp, class _Alloc>
using __pointer = __detected_or_t<_Tp*, __pointer_member, __libcpp_remove_reference_t<_Alloc> >;
using __pointer _LIBCPP_NODEBUG = __detected_or_t<_Tp *, __pointer_member, __libcpp_remove_reference_t<_Alloc> >;

// __const_pointer
_LIBCPP_ALLOCATOR_TRAITS_HAS_XXX(__has_const_pointer, const_pointer);
Expand All @@ -73,7 +73,7 @@ struct __void_pointer {
template <class _Ptr, class _Alloc>
struct __void_pointer<_Ptr, _Alloc, false> {
#ifdef _LIBCPP_CXX03_LANG
using type _LIBCPP_NODEBUG = typename pointer_traits<_Ptr>::template rebind<void>::other;
using type = typename pointer_traits<_Ptr>::template rebind<void>::other;
#else
using type _LIBCPP_NODEBUG = typename pointer_traits<_Ptr>::template rebind<void>;
#endif
Expand All @@ -88,18 +88,18 @@ struct __const_void_pointer {
template <class _Ptr, class _Alloc>
struct __const_void_pointer<_Ptr, _Alloc, false> {
#ifdef _LIBCPP_CXX03_LANG
using type _LIBCPP_NODEBUG = typename pointer_traits<_Ptr>::template rebind<const void>::other;
using type = typename pointer_traits<_Ptr>::template rebind<const void>::other;
#else
using type _LIBCPP_NODEBUG = typename pointer_traits<_Ptr>::template rebind<const void>;
#endif
};

// __size_type
template <class _Tp>
using __size_type_member = typename _Tp::size_type;
using __size_type_member _LIBCPP_NODEBUG = typename _Tp::size_type;

template <class _Alloc, class _DiffType>
using __size_type = __detected_or_t<__make_unsigned_t<_DiffType>, __size_type_member, _Alloc>;
using __size_type _LIBCPP_NODEBUG = __detected_or_t<__make_unsigned_t<_DiffType>, __size_type_member, _Alloc>;

// __alloc_traits_difference_type
_LIBCPP_ALLOCATOR_TRAITS_HAS_XXX(__has_alloc_traits_difference_type, difference_type);
Expand All @@ -114,33 +114,31 @@ struct __alloc_traits_difference_type<_Alloc, _Ptr, true> {

// __propagate_on_container_copy_assignment
template <class _Tp>
using __propagate_on_container_copy_assignment_member = typename _Tp::propagate_on_container_copy_assignment;
using __propagate_on_container_copy_assignment_member _LIBCPP_NODEBUG = typename _Tp::propagate_on_container_copy_assignment;

template <class _Alloc>
using __propagate_on_container_copy_assignment =
__detected_or_t<false_type, __propagate_on_container_copy_assignment_member, _Alloc>;
using __propagate_on_container_copy_assignment _LIBCPP_NODEBUG = __detected_or_t<false_type, __propagate_on_container_copy_assignment_member, _Alloc>;

// __propagate_on_container_move_assignment
template <class _Tp>
using __propagate_on_container_move_assignment_member = typename _Tp::propagate_on_container_move_assignment;
using __propagate_on_container_move_assignment_member _LIBCPP_NODEBUG = typename _Tp::propagate_on_container_move_assignment;

template <class _Alloc>
using __propagate_on_container_move_assignment =
__detected_or_t<false_type, __propagate_on_container_move_assignment_member, _Alloc>;
using __propagate_on_container_move_assignment _LIBCPP_NODEBUG = __detected_or_t<false_type, __propagate_on_container_move_assignment_member, _Alloc>;

// __propagate_on_container_swap
template <class _Tp>
using __propagate_on_container_swap_member = typename _Tp::propagate_on_container_swap;
using __propagate_on_container_swap_member _LIBCPP_NODEBUG = typename _Tp::propagate_on_container_swap;

template <class _Alloc>
using __propagate_on_container_swap = __detected_or_t<false_type, __propagate_on_container_swap_member, _Alloc>;
using __propagate_on_container_swap _LIBCPP_NODEBUG = __detected_or_t<false_type, __propagate_on_container_swap_member, _Alloc>;

// __is_always_equal
template <class _Tp>
using __is_always_equal_member = typename _Tp::is_always_equal;
using __is_always_equal_member _LIBCPP_NODEBUG = typename _Tp::is_always_equal;

template <class _Alloc>
using __is_always_equal = __detected_or_t<typename is_empty<_Alloc>::type, __is_always_equal_member, _Alloc>;
using __is_always_equal _LIBCPP_NODEBUG = __detected_or_t<typename is_empty<_Alloc>::type, __is_always_equal_member, _Alloc>;

// __allocator_traits_rebind
_LIBCPP_SUPPRESS_DEPRECATED_PUSH
Expand All @@ -165,7 +163,7 @@ struct __allocator_traits_rebind<_Alloc<_Tp, _Args...>, _Up, false> {
_LIBCPP_SUPPRESS_DEPRECATED_POP

template <class _Alloc, class _Tp>
using __allocator_traits_rebind_t = typename __allocator_traits_rebind<_Alloc, _Tp>::type;
using __allocator_traits_rebind_t _LIBCPP_NODEBUG = typename __allocator_traits_rebind<_Alloc, _Tp>::type;

_LIBCPP_SUPPRESS_DEPRECATED_PUSH

Expand Down Expand Up @@ -232,18 +230,18 @@ _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(allocation_result);

template <class _Alloc>
struct _LIBCPP_TEMPLATE_VIS allocator_traits {
using allocator_type = _Alloc;
using value_type = typename allocator_type::value_type;
using pointer = __pointer<value_type, allocator_type>;
using const_pointer = typename __const_pointer<value_type, pointer, allocator_type>::type;
using void_pointer = typename __void_pointer<pointer, allocator_type>::type;
using const_void_pointer = typename __const_void_pointer<pointer, allocator_type>::type;
using difference_type = typename __alloc_traits_difference_type<allocator_type, pointer>::type;
using size_type = __size_type<allocator_type, difference_type>;
using propagate_on_container_copy_assignment = __propagate_on_container_copy_assignment<allocator_type>;
using propagate_on_container_move_assignment = __propagate_on_container_move_assignment<allocator_type>;
using propagate_on_container_swap = __propagate_on_container_swap<allocator_type>;
using is_always_equal = __is_always_equal<allocator_type>;
using allocator_type _LIBCPP_NODEBUG = _Alloc;
using value_type _LIBCPP_NODEBUG = typename allocator_type::value_type;
using pointer _LIBCPP_NODEBUG = __pointer<value_type, allocator_type>;
using const_pointer _LIBCPP_NODEBUG = typename __const_pointer<value_type, pointer, allocator_type>::type;
using void_pointer _LIBCPP_NODEBUG = typename __void_pointer<pointer, allocator_type>::type;
using const_void_pointer _LIBCPP_NODEBUG = typename __const_void_pointer<pointer, allocator_type>::type;
using difference_type _LIBCPP_NODEBUG = typename __alloc_traits_difference_type<allocator_type, pointer>::type;
using size_type _LIBCPP_NODEBUG = __size_type<allocator_type, difference_type>;
using propagate_on_container_copy_assignment _LIBCPP_NODEBUG = __propagate_on_container_copy_assignment<allocator_type>;
using propagate_on_container_move_assignment _LIBCPP_NODEBUG = __propagate_on_container_move_assignment<allocator_type>;
using propagate_on_container_swap _LIBCPP_NODEBUG = __propagate_on_container_swap<allocator_type>;
using is_always_equal _LIBCPP_NODEBUG = __is_always_equal<allocator_type>;

#ifndef _LIBCPP_CXX03_LANG
template <class _Tp>
Expand All @@ -253,11 +251,11 @@ struct _LIBCPP_TEMPLATE_VIS allocator_traits {
#else // _LIBCPP_CXX03_LANG
template <class _Tp>
struct rebind_alloc {
using other = __allocator_traits_rebind_t<allocator_type, _Tp>;
using other _LIBCPP_NODEBUG = __allocator_traits_rebind_t<allocator_type, _Tp>;
};
template <class _Tp>
struct rebind_traits {
using other = allocator_traits<typename rebind_alloc<_Tp>::other>;
using other _LIBCPP_NODEBUG = allocator_traits<typename rebind_alloc<_Tp>::other>;
};
#endif // _LIBCPP_CXX03_LANG

Expand Down Expand Up @@ -352,15 +350,15 @@ struct _LIBCPP_TEMPLATE_VIS allocator_traits {

#ifndef _LIBCPP_CXX03_LANG
template <class _Traits, class _Tp>
using __rebind_alloc _LIBCPP_NODEBUG = typename _Traits::template rebind_alloc<_Tp>;
using __rebind_alloc = typename _Traits::template rebind_alloc<_Tp>;
#else
template <class _Traits, class _Tp>
using __rebind_alloc = typename _Traits::template rebind_alloc<_Tp>::other;
using __rebind_alloc _LIBCPP_NODEBUG = typename _Traits::template rebind_alloc<_Tp>::other;
#endif

template <class _Alloc>
struct __check_valid_allocator : true_type {
using _Traits = std::allocator_traits<_Alloc>;
using _Traits _LIBCPP_NODEBUG = std::allocator_traits<_Alloc>;
static_assert(is_same<_Alloc, __rebind_alloc<_Traits, typename _Traits::value_type> >::value,
"[allocator.requirements] states that rebinding an allocator to the same type should result in the "
"original allocator");
Expand Down
2 changes: 1 addition & 1 deletion libcxx/include/__memory/unique_ptr.h
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ class _LIBCPP_UNIQUE_PTR_TRIVIAL_ABI _LIBCPP_TEMPLATE_VIS unique_ptr<_Tp[], _Dp>
public:
typedef _Tp element_type;
typedef _Dp deleter_type;
using pointer = __pointer<_Tp, deleter_type>;
using pointer _LIBCPP_NODEBUG = __pointer<_Tp, deleter_type>;

// A unique_ptr contains the following members which may be trivially relocatable:
// - pointer: this may be trivially relocatable, so it's checked
Expand Down
6 changes: 3 additions & 3 deletions libcxx/include/__type_traits/detected_or.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@ _LIBCPP_BEGIN_NAMESPACE_STD

template <class _Default, class _Void, template <class...> class _Op, class... _Args>
struct __detector {
using type = _Default;
using type _LIBCPP_NODEBUG = _Default;
};

template <class _Default, template <class...> class _Op, class... _Args>
struct __detector<_Default, __void_t<_Op<_Args...> >, _Op, _Args...> {
using type = _Op<_Args...>;
using type _LIBCPP_NODEBUG = _Op<_Args...>;
};

template <class _Default, template <class...> class _Op, class... _Args>
using __detected_or_t = typename __detector<_Default, void, _Op, _Args...>::type;
using __detected_or_t _LIBCPP_NODEBUG = typename __detector<_Default, void, _Op, _Args...>::type;

_LIBCPP_END_NAMESPACE_STD

Expand Down
Loading