Skip to content

[libc++] Add [[gnu::nodebug]] on type traits #128502

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 1 commit into from
Mar 23, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 2 additions & 1 deletion libcxx/docs/CodingGuidelines.rst
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ Library-internal type aliases should be annotated with ``_LIBCPP_NODEBUG``
Libc++ has lots of internal type aliases. Accumulated, these can result in significant amounts of debug information that
users generally don't care about, since users don't try to debug standard library facilities in most cases. For that
reason, all library-internal type aliases that aren't function-local should be annotated with ``_LIBCPP_NODEBUG`` to
prevent compilers from generating said debug information.
prevent compilers from generating said debug information. Aliases inside type traits (i.e. aliases named ``type``)
should be annotated for the same reason.

This is enforced by the clang-tidy check ``libcpp-nodebug-on-aliases``.
8 changes: 4 additions & 4 deletions libcxx/include/__algorithm/simd_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,20 +51,20 @@ struct __get_as_integer_type_impl;

template <>
struct __get_as_integer_type_impl<1> {
using type = uint8_t;
using type _LIBCPP_NODEBUG = uint8_t;
};

template <>
struct __get_as_integer_type_impl<2> {
using type = uint16_t;
using type _LIBCPP_NODEBUG = uint16_t;
};
template <>
struct __get_as_integer_type_impl<4> {
using type = uint32_t;
using type _LIBCPP_NODEBUG = uint32_t;
};
template <>
struct __get_as_integer_type_impl<8> {
using type = uint64_t;
using type _LIBCPP_NODEBUG = uint64_t;
};

template <class _Tp>
Expand Down
2 changes: 1 addition & 1 deletion libcxx/include/__compare/common_comparison_category.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ _LIBCPP_HIDE_FROM_ABI constexpr auto __get_comp_type() {
// [cmp.common], common comparison category type
template <class... _Ts>
struct _LIBCPP_TEMPLATE_VIS common_comparison_category {
using type = decltype(__comp_detail::__get_comp_type<_Ts...>());
using type _LIBCPP_NODEBUG = decltype(__comp_detail::__get_comp_type<_Ts...>());
};

template <class... _Ts>
Expand Down
3 changes: 2 additions & 1 deletion libcxx/include/__compare/compare_three_way_result.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ struct _LIBCPP_HIDE_FROM_ABI __compare_three_way_result<
_Tp,
_Up,
decltype(std::declval<__make_const_lvalue_ref<_Tp>>() <=> std::declval<__make_const_lvalue_ref<_Up>>(), void())> {
using type = decltype(std::declval<__make_const_lvalue_ref<_Tp>>() <=> std::declval<__make_const_lvalue_ref<_Up>>());
using type _LIBCPP_NODEBUG =
decltype(std::declval<__make_const_lvalue_ref<_Tp>>() <=> std::declval<__make_const_lvalue_ref<_Up>>());
};

template <class _Tp, class _Up = _Tp>
Expand Down
6 changes: 3 additions & 3 deletions libcxx/include/__functional/bind.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ struct __mu_return_invokable // false

template <class _Ti, class... _Uj>
struct __mu_return_invokable<true, _Ti, _Uj...> {
using type = __invoke_result_t<_Ti&, _Uj...>;
using type _LIBCPP_NODEBUG = __invoke_result_t<_Ti&, _Uj...>;
};

template <class _Ti, class... _Uj>
Expand Down Expand Up @@ -181,12 +181,12 @@ struct __bind_return;

template <class _Fp, class... _BoundArgs, class _TupleUj>
struct __bind_return<_Fp, tuple<_BoundArgs...>, _TupleUj, true> {
using type = __invoke_result_t< _Fp&, typename __mu_return< _BoundArgs, _TupleUj >::type... >;
using type _LIBCPP_NODEBUG = __invoke_result_t<_Fp&, typename __mu_return<_BoundArgs, _TupleUj>::type...>;
};

template <class _Fp, class... _BoundArgs, class _TupleUj>
struct __bind_return<_Fp, const tuple<_BoundArgs...>, _TupleUj, true> {
using type = __invoke_result_t< _Fp&, typename __mu_return< const _BoundArgs, _TupleUj >::type... >;
using type _LIBCPP_NODEBUG = __invoke_result_t<_Fp&, typename __mu_return<const _BoundArgs, _TupleUj>::type...>;
};

template <class _Fp, class _BoundArgs, size_t... _Indx, class _Args>
Expand Down
4 changes: 2 additions & 2 deletions libcxx/include/__iterator/common_iterator.h
Original file line number Diff line number Diff line change
Expand Up @@ -272,13 +272,13 @@ concept __common_iter_has_ptr_op = requires(const common_iterator<_Iter, _Sent>&

template <class, class>
struct __arrow_type_or_void {
using type = void;
using type _LIBCPP_NODEBUG = void;
};

template <class _Iter, class _Sent>
requires __common_iter_has_ptr_op<_Iter, _Sent>
struct __arrow_type_or_void<_Iter, _Sent> {
using type = decltype(std::declval<const common_iterator<_Iter, _Sent>&>().operator->());
using type _LIBCPP_NODEBUG = decltype(std::declval<const common_iterator<_Iter, _Sent>&>().operator->());
};

template <input_iterator _Iter, class _Sent>
Expand Down
7 changes: 4 additions & 3 deletions libcxx/include/__iterator/concepts.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,13 @@ concept __specialization_of_projected = requires {

template <class _Tp>
struct __indirect_value_t_impl {
using type = iter_value_t<_Tp>&;
using type _LIBCPP_NODEBUG = iter_value_t<_Tp>&;
};
template <__specialization_of_projected _Tp>
struct __indirect_value_t_impl<_Tp> {
using type = invoke_result_t<__projected_projection_t<_Tp>&,
typename __indirect_value_t_impl<__projected_iterator_t<_Tp>>::type>;
using type _LIBCPP_NODEBUG =
invoke_result_t<__projected_projection_t<_Tp>&,
typename __indirect_value_t_impl<__projected_iterator_t<_Tp>>::type>;
};

template <indirectly_readable _Tp>
Expand Down
38 changes: 20 additions & 18 deletions libcxx/include/__iterator/iterator_traits.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ struct _LIBCPP_TEMPLATE_VIS contiguous_iterator_tag : public random_access_itera

template <class _Iter>
struct __iter_traits_cache {
using type = _If< __is_primary_template<iterator_traits<_Iter> >::value, _Iter, iterator_traits<_Iter> >;
using type _LIBCPP_NODEBUG =
_If<__is_primary_template<iterator_traits<_Iter> >::value, _Iter, iterator_traits<_Iter> >;
};
template <class _Iter>
using _ITER_TRAITS _LIBCPP_NODEBUG = typename __iter_traits_cache<_Iter>::type;
Expand All @@ -101,9 +102,10 @@ struct __test_iter_concept : _IsValidExpansion<_Tester::template _Apply, _Iter>,

template <class _Iter>
struct __iter_concept_cache {
using type = _Or< __test_iter_concept<_Iter, __iter_concept_concept_test>,
__test_iter_concept<_Iter, __iter_concept_category_test>,
__test_iter_concept<_Iter, __iter_concept_random_fallback> >;
using type _LIBCPP_NODEBUG =
_Or<__test_iter_concept<_Iter, __iter_concept_concept_test>,
__test_iter_concept<_Iter, __iter_concept_category_test>,
__test_iter_concept<_Iter, __iter_concept_random_fallback> >;
};

template <class _Iter>
Expand Down Expand Up @@ -221,12 +223,12 @@ concept __specifies_members = requires {

template <class>
struct __iterator_traits_member_pointer_or_void {
using type = void;
using type _LIBCPP_NODEBUG = void;
};

template <__has_member_pointer _Tp>
struct __iterator_traits_member_pointer_or_void<_Tp> {
using type = typename _Tp::pointer;
using type _LIBCPP_NODEBUG = typename _Tp::pointer;
};

template <class _Tp>
Expand All @@ -239,63 +241,63 @@ concept __cpp17_input_iterator_missing_members =
// Otherwise, `pointer` names `void`.
template <class>
struct __iterator_traits_member_pointer_or_arrow_or_void {
using type = void;
using type _LIBCPP_NODEBUG = void;
};

// [iterator.traits]/3.2.1
// If the qualified-id `I::pointer` is valid and denotes a type, `pointer` names that type.
template <__has_member_pointer _Ip>
struct __iterator_traits_member_pointer_or_arrow_or_void<_Ip> {
using type = typename _Ip::pointer;
using type _LIBCPP_NODEBUG = typename _Ip::pointer;
};

// Otherwise, if `decltype(declval<I&>().operator->())` is well-formed, then `pointer` names that
// type.
template <class _Ip>
requires requires(_Ip& __i) { __i.operator->(); } && (!__has_member_pointer<_Ip>)
struct __iterator_traits_member_pointer_or_arrow_or_void<_Ip> {
using type = decltype(std::declval<_Ip&>().operator->());
using type _LIBCPP_NODEBUG = decltype(std::declval<_Ip&>().operator->());
};

// Otherwise, `reference` names `iter-reference-t<I>`.
template <class _Ip>
struct __iterator_traits_member_reference {
using type = iter_reference_t<_Ip>;
using type _LIBCPP_NODEBUG = iter_reference_t<_Ip>;
};

// [iterator.traits]/3.2.2
// If the qualified-id `I::reference` is valid and denotes a type, `reference` names that type.
template <__has_member_reference _Ip>
struct __iterator_traits_member_reference<_Ip> {
using type = typename _Ip::reference;
using type _LIBCPP_NODEBUG = typename _Ip::reference;
};

// [iterator.traits]/3.2.3.4
// input_iterator_tag
template <class _Ip>
struct __deduce_iterator_category {
using type = input_iterator_tag;
using type _LIBCPP_NODEBUG = input_iterator_tag;
};

// [iterator.traits]/3.2.3.1
// `random_access_iterator_tag` if `I` satisfies `cpp17-random-access-iterator`, or otherwise
template <__iterator_traits_detail::__cpp17_random_access_iterator _Ip>
struct __deduce_iterator_category<_Ip> {
using type = random_access_iterator_tag;
using type _LIBCPP_NODEBUG = random_access_iterator_tag;
};

// [iterator.traits]/3.2.3.2
// `bidirectional_iterator_tag` if `I` satisfies `cpp17-bidirectional-iterator`, or otherwise
template <__iterator_traits_detail::__cpp17_bidirectional_iterator _Ip>
struct __deduce_iterator_category<_Ip> {
using type = bidirectional_iterator_tag;
using type _LIBCPP_NODEBUG = bidirectional_iterator_tag;
};

// [iterator.traits]/3.2.3.3
// `forward_iterator_tag` if `I` satisfies `cpp17-forward-iterator`, or otherwise
template <__iterator_traits_detail::__cpp17_forward_iterator _Ip>
struct __deduce_iterator_category<_Ip> {
using type = forward_iterator_tag;
using type _LIBCPP_NODEBUG = forward_iterator_tag;
};

template <class _Ip>
Expand All @@ -306,21 +308,21 @@ struct __iterator_traits_iterator_category : __deduce_iterator_category<_Ip> {};
// that type.
template <__has_member_iterator_category _Ip>
struct __iterator_traits_iterator_category<_Ip> {
using type = typename _Ip::iterator_category;
using type _LIBCPP_NODEBUG = typename _Ip::iterator_category;
};

// otherwise, it names void.
template <class>
struct __iterator_traits_difference_type {
using type = void;
using type _LIBCPP_NODEBUG = void;
};

// If the qualified-id `incrementable_traits<I>::difference_type` is valid and denotes a type, then
// `difference_type` names that type;
template <class _Ip>
requires requires { typename incrementable_traits<_Ip>::difference_type; }
struct __iterator_traits_difference_type<_Ip> {
using type = typename incrementable_traits<_Ip>::difference_type;
using type _LIBCPP_NODEBUG = typename incrementable_traits<_Ip>::difference_type;
};

// [iterator.traits]/3.4
Expand Down
4 changes: 2 additions & 2 deletions libcxx/include/__mdspan/extents.h
Original file line number Diff line number Diff line change
Expand Up @@ -440,13 +440,13 @@ struct __make_dextents;

template <class _IndexType, size_t _Rank, size_t... _ExtentsPack>
struct __make_dextents< _IndexType, _Rank, extents<_IndexType, _ExtentsPack...>> {
using type =
using type _LIBCPP_NODEBUG =
typename __make_dextents< _IndexType, _Rank - 1, extents<_IndexType, dynamic_extent, _ExtentsPack...>>::type;
};

template <class _IndexType, size_t... _ExtentsPack>
struct __make_dextents< _IndexType, 0, extents<_IndexType, _ExtentsPack...>> {
using type = extents<_IndexType, _ExtentsPack...>;
using type _LIBCPP_NODEBUG = extents<_IndexType, _ExtentsPack...>;
};

} // namespace __mdspan_detail
Expand Down
6 changes: 3 additions & 3 deletions libcxx/include/__memory/pointer_traits.h
Original file line number Diff line number Diff line change
Expand Up @@ -259,20 +259,20 @@ struct __pointer_of {};
template <class _Tp>
requires(__has_pointer<_Tp>::value)
struct __pointer_of<_Tp> {
using type = typename _Tp::pointer;
using type _LIBCPP_NODEBUG = typename _Tp::pointer;
};

template <class _Tp>
requires(!__has_pointer<_Tp>::value && __has_element_type<_Tp>::value)
struct __pointer_of<_Tp> {
using type = typename _Tp::element_type*;
using type _LIBCPP_NODEBUG = typename _Tp::element_type*;
};

template <class _Tp>
requires(!__has_pointer<_Tp>::value && !__has_element_type<_Tp>::value &&
__has_element_type<pointer_traits<_Tp>>::value)
struct __pointer_of<_Tp> {
using type = typename pointer_traits<_Tp>::element_type*;
using type _LIBCPP_NODEBUG = typename pointer_traits<_Tp>::element_type*;
};

template <typename _Tp>
Expand Down
8 changes: 4 additions & 4 deletions libcxx/include/__ranges/drop_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,22 +185,22 @@ struct __passthrough_type;

template <class _Tp, size_t _Extent>
struct __passthrough_type<span<_Tp, _Extent>> {
using type = span<_Tp>;
using type _LIBCPP_NODEBUG = span<_Tp>;
};

template <class _CharT, class _Traits>
struct __passthrough_type<basic_string_view<_CharT, _Traits>> {
using type = basic_string_view<_CharT, _Traits>;
using type _LIBCPP_NODEBUG = basic_string_view<_CharT, _Traits>;
};

template <class _Np, class _Bound>
struct __passthrough_type<iota_view<_Np, _Bound>> {
using type = iota_view<_Np, _Bound>;
using type _LIBCPP_NODEBUG = iota_view<_Np, _Bound>;
};

template <class _Iter, class _Sent, subrange_kind _Kind>
struct __passthrough_type<subrange<_Iter, _Sent, _Kind>> {
using type = subrange<_Iter, _Sent, _Kind>;
using type _LIBCPP_NODEBUG = subrange<_Iter, _Sent, _Kind>;
};

template <class _Tp>
Expand Down
4 changes: 2 additions & 2 deletions libcxx/include/__ranges/repeat_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ concept __integer_like_with_usable_difference_type =

template <class _Tp>
struct __repeat_view_iterator_difference {
using type = _IotaDiffT<_Tp>;
using type _LIBCPP_NODEBUG = _IotaDiffT<_Tp>;
};

template <__signed_integer_like _Tp>
struct __repeat_view_iterator_difference<_Tp> {
using type = _Tp;
using type _LIBCPP_NODEBUG = _Tp;
};

template <class _Tp>
Expand Down
4 changes: 2 additions & 2 deletions libcxx/include/__ranges/reverse_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,13 @@ inline constexpr bool __is_unsized_reverse_subrange<subrange<reverse_iterator<_I

template <class _Tp>
struct __unwrapped_reverse_subrange {
using type =
using type _LIBCPP_NODEBUG =
void; // avoid SFINAE-ing out the overload below -- let the concept requirements do it for better diagnostics
};

template <class _Iter, subrange_kind _Kind>
struct __unwrapped_reverse_subrange<subrange<reverse_iterator<_Iter>, reverse_iterator<_Iter>, _Kind>> {
using type = subrange<_Iter, _Iter, _Kind>;
using type _LIBCPP_NODEBUG = subrange<_Iter, _Iter, _Kind>;
};

struct __fn : __range_adaptor_closure<__fn> {
Expand Down
8 changes: 4 additions & 4 deletions libcxx/include/__ranges/subrange.h
Original file line number Diff line number Diff line change
Expand Up @@ -247,22 +247,22 @@ struct tuple_size<ranges::subrange<_Ip, _Sp, _Kp>> : integral_constant<size_t, 2

template <class _Ip, class _Sp, ranges::subrange_kind _Kp>
struct tuple_element<0, ranges::subrange<_Ip, _Sp, _Kp>> {
using type = _Ip;
using type _LIBCPP_NODEBUG = _Ip;
};

template <class _Ip, class _Sp, ranges::subrange_kind _Kp>
struct tuple_element<1, ranges::subrange<_Ip, _Sp, _Kp>> {
using type = _Sp;
using type _LIBCPP_NODEBUG = _Sp;
};

template <class _Ip, class _Sp, ranges::subrange_kind _Kp>
struct tuple_element<0, const ranges::subrange<_Ip, _Sp, _Kp>> {
using type = _Ip;
using type _LIBCPP_NODEBUG = _Ip;
};

template <class _Ip, class _Sp, ranges::subrange_kind _Kp>
struct tuple_element<1, const ranges::subrange<_Ip, _Sp, _Kp>> {
using type = _Sp;
using type _LIBCPP_NODEBUG = _Sp;
};

#endif // _LIBCPP_STD_VER >= 20
Expand Down
6 changes: 3 additions & 3 deletions libcxx/include/__ranges/take_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -229,18 +229,18 @@ struct __passthrough_type;

template <class _Tp, size_t _Extent>
struct __passthrough_type<span<_Tp, _Extent>> {
using type = span<_Tp>;
using type _LIBCPP_NODEBUG = span<_Tp>;
};

template <class _CharT, class _Traits>
struct __passthrough_type<basic_string_view<_CharT, _Traits>> {
using type = basic_string_view<_CharT, _Traits>;
using type _LIBCPP_NODEBUG = basic_string_view<_CharT, _Traits>;
};

template <class _Iter, class _Sent, subrange_kind _Kind>
requires requires { typename subrange<_Iter>; }
struct __passthrough_type<subrange<_Iter, _Sent, _Kind>> {
using type = subrange<_Iter>;
using type _LIBCPP_NODEBUG = subrange<_Iter>;
};

template <class _Tp>
Expand Down
Loading
Loading