[libcxx-commits] [libcxx] [libc++] Add [[gnu::nodebug]] on type traits (PR #128502)

Nikolas Klauser via libcxx-commits libcxx-commits at lists.llvm.org
Wed Feb 26 04:24:18 PST 2025


https://github.com/philnik777 updated https://github.com/llvm/llvm-project/pull/128502

>From 359dd1dfe53c7492e98328e23031698f2d0017fa Mon Sep 17 00:00:00 2001
From: Nikolas Klauser <nikolasklauser at berlin.de>
Date: Tue, 10 Dec 2024 21:02:07 +0100
Subject: [PATCH] [libc++] Add [[gnu::nodebug]] on type traits

---
 libcxx/docs/CodingGuidelines.rst              |  3 +-
 libcxx/include/__algorithm/simd_utils.h       |  8 ++--
 .../__compare/common_comparison_category.h    |  2 +-
 .../__compare/compare_three_way_result.h      |  3 +-
 libcxx/include/__functional/bind.h            |  6 +--
 libcxx/include/__iterator/common_iterator.h   |  4 +-
 libcxx/include/__iterator/concepts.h          |  7 ++--
 libcxx/include/__iterator/iterator_traits.h   | 38 ++++++++++---------
 libcxx/include/__mdspan/extents.h             |  4 +-
 libcxx/include/__memory/pointer_traits.h      |  6 +--
 libcxx/include/__ranges/drop_view.h           |  8 ++--
 libcxx/include/__ranges/repeat_view.h         |  4 +-
 libcxx/include/__ranges/reverse_view.h        |  4 +-
 libcxx/include/__ranges/subrange.h            |  8 ++--
 libcxx/include/__ranges/take_view.h           |  6 +--
 libcxx/include/__ranges/transform_view.h      |  8 ++--
 libcxx/include/__tuple/make_tuple_types.h     |  2 +-
 .../__type_traits/add_rvalue_reference.h      |  2 +-
 .../include/__type_traits/common_reference.h  |  8 ++--
 libcxx/include/__type_traits/common_type.h    |  2 +-
 .../include/__type_traits/strip_signature.h   | 36 +++++++++---------
 libcxx/include/__utility/pair.h               |  4 +-
 libcxx/include/array                          |  2 +-
 libcxx/include/complex                        |  2 +-
 .../include/experimental/__simd/declaration.h |  2 +-
 libcxx/include/tuple                          |  4 +-
 libcxx/include/variant                        |  2 +-
 .../clang_tidy_checks/nodebug_on_aliases.cpp  | 19 ++++++++++
 28 files changed, 114 insertions(+), 90 deletions(-)

diff --git a/libcxx/docs/CodingGuidelines.rst b/libcxx/docs/CodingGuidelines.rst
index 0c85cd07c0f61..2266a7107bc66 100644
--- a/libcxx/docs/CodingGuidelines.rst
+++ b/libcxx/docs/CodingGuidelines.rst
@@ -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. alises named ``type``) should
+be annotated for the same reason.
 
 This is enforced by the clang-tidy check ``libcpp-nodebug-on-aliases``.
diff --git a/libcxx/include/__algorithm/simd_utils.h b/libcxx/include/__algorithm/simd_utils.h
index 4e03723a32854..4dac7eb8e6b4e 100644
--- a/libcxx/include/__algorithm/simd_utils.h
+++ b/libcxx/include/__algorithm/simd_utils.h
@@ -53,20 +53,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>
diff --git a/libcxx/include/__compare/common_comparison_category.h b/libcxx/include/__compare/common_comparison_category.h
index 6ddf9b9d45894..a49499ea4198d 100644
--- a/libcxx/include/__compare/common_comparison_category.h
+++ b/libcxx/include/__compare/common_comparison_category.h
@@ -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>
diff --git a/libcxx/include/__compare/compare_three_way_result.h b/libcxx/include/__compare/compare_three_way_result.h
index 6ee2eff00302d..5327cc57eb580 100644
--- a/libcxx/include/__compare/compare_three_way_result.h
+++ b/libcxx/include/__compare/compare_three_way_result.h
@@ -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>
diff --git a/libcxx/include/__functional/bind.h b/libcxx/include/__functional/bind.h
index a3c327ab40cc9..596cce03cdb58 100644
--- a/libcxx/include/__functional/bind.h
+++ b/libcxx/include/__functional/bind.h
@@ -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>
@@ -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>
diff --git a/libcxx/include/__iterator/common_iterator.h b/libcxx/include/__iterator/common_iterator.h
index 31fc8267e5afb..7ec384b2034a0 100644
--- a/libcxx/include/__iterator/common_iterator.h
+++ b/libcxx/include/__iterator/common_iterator.h
@@ -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>
diff --git a/libcxx/include/__iterator/concepts.h b/libcxx/include/__iterator/concepts.h
index 6e5ac1d3af37b..9e4c456e211b6 100644
--- a/libcxx/include/__iterator/concepts.h
+++ b/libcxx/include/__iterator/concepts.h
@@ -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>
diff --git a/libcxx/include/__iterator/iterator_traits.h b/libcxx/include/__iterator/iterator_traits.h
index db68dd2c377ac..4a9fa3cc8f244 100644
--- a/libcxx/include/__iterator/iterator_traits.h
+++ b/libcxx/include/__iterator/iterator_traits.h
@@ -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;
@@ -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>
@@ -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>
@@ -239,14 +241,14 @@ 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
@@ -254,48 +256,48 @@ struct __iterator_traits_member_pointer_or_arrow_or_void<_Ip> {
 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>
@@ -306,13 +308,13 @@ 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
@@ -320,7 +322,7 @@ struct __iterator_traits_difference_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
diff --git a/libcxx/include/__mdspan/extents.h b/libcxx/include/__mdspan/extents.h
index 65a697769bdaa..00454004851d5 100644
--- a/libcxx/include/__mdspan/extents.h
+++ b/libcxx/include/__mdspan/extents.h
@@ -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
diff --git a/libcxx/include/__memory/pointer_traits.h b/libcxx/include/__memory/pointer_traits.h
index afe3d1bf8a2de..d20bac8e4cba2 100644
--- a/libcxx/include/__memory/pointer_traits.h
+++ b/libcxx/include/__memory/pointer_traits.h
@@ -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>
diff --git a/libcxx/include/__ranges/drop_view.h b/libcxx/include/__ranges/drop_view.h
index 3f963d04fff24..42ada9299a779 100644
--- a/libcxx/include/__ranges/drop_view.h
+++ b/libcxx/include/__ranges/drop_view.h
@@ -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>
diff --git a/libcxx/include/__ranges/repeat_view.h b/libcxx/include/__ranges/repeat_view.h
index 61a8b6357105a..56b09701c8090 100644
--- a/libcxx/include/__ranges/repeat_view.h
+++ b/libcxx/include/__ranges/repeat_view.h
@@ -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>
diff --git a/libcxx/include/__ranges/reverse_view.h b/libcxx/include/__ranges/reverse_view.h
index 80d54b9a6c83a..c36ba77dd8f6d 100644
--- a/libcxx/include/__ranges/reverse_view.h
+++ b/libcxx/include/__ranges/reverse_view.h
@@ -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> {
diff --git a/libcxx/include/__ranges/subrange.h b/libcxx/include/__ranges/subrange.h
index 2d006d3570a79..790fcebff2b8b 100644
--- a/libcxx/include/__ranges/subrange.h
+++ b/libcxx/include/__ranges/subrange.h
@@ -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
diff --git a/libcxx/include/__ranges/take_view.h b/libcxx/include/__ranges/take_view.h
index 5892c1e31fae1..85723dc5e36b6 100644
--- a/libcxx/include/__ranges/take_view.h
+++ b/libcxx/include/__ranges/take_view.h
@@ -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>
diff --git a/libcxx/include/__ranges/transform_view.h b/libcxx/include/__ranges/transform_view.h
index 4ae21e92b69d5..74a3b4f684fd0 100644
--- a/libcxx/include/__ranges/transform_view.h
+++ b/libcxx/include/__ranges/transform_view.h
@@ -136,22 +136,22 @@ transform_view(_Range&&, _Fn) -> transform_view<views::all_t<_Range>, _Fn>;
 
 template <class _View>
 struct __transform_view_iterator_concept {
-  using type = input_iterator_tag;
+  using type _LIBCPP_NODEBUG = input_iterator_tag;
 };
 
 template <random_access_range _View>
 struct __transform_view_iterator_concept<_View> {
-  using type = random_access_iterator_tag;
+  using type _LIBCPP_NODEBUG = random_access_iterator_tag;
 };
 
 template <bidirectional_range _View>
 struct __transform_view_iterator_concept<_View> {
-  using type = bidirectional_iterator_tag;
+  using type _LIBCPP_NODEBUG = bidirectional_iterator_tag;
 };
 
 template <forward_range _View>
 struct __transform_view_iterator_concept<_View> {
-  using type = forward_iterator_tag;
+  using type _LIBCPP_NODEBUG = forward_iterator_tag;
 };
 
 template <class, class>
diff --git a/libcxx/include/__tuple/make_tuple_types.h b/libcxx/include/__tuple/make_tuple_types.h
index ff95ca4313a5b..a5c9bcf23a6eb 100644
--- a/libcxx/include/__tuple/make_tuple_types.h
+++ b/libcxx/include/__tuple/make_tuple_types.h
@@ -60,7 +60,7 @@ struct __make_tuple_types {
   static_assert(_Sp <= _Ep, "__make_tuple_types input error");
   using _RawTp _LIBCPP_NODEBUG = __remove_cvref_t<_Tp>;
   using _Maker _LIBCPP_NODEBUG = __make_tuple_types_flat<_RawTp, typename __make_tuple_indices<_Ep, _Sp>::type>;
-  using type                   = typename _Maker::template __apply_quals<_Tp>;
+  using type _LIBCPP_NODEBUG   = typename _Maker::template __apply_quals<_Tp>;
 };
 
 template <class... _Types, size_t _Ep>
diff --git a/libcxx/include/__type_traits/add_rvalue_reference.h b/libcxx/include/__type_traits/add_rvalue_reference.h
index ed4f8633bce1f..12432929afa3c 100644
--- a/libcxx/include/__type_traits/add_rvalue_reference.h
+++ b/libcxx/include/__type_traits/add_rvalue_reference.h
@@ -41,7 +41,7 @@ using __add_rvalue_reference_t = typename __add_rvalue_reference_impl<_Tp>::type
 
 template <class _Tp>
 struct _LIBCPP_NO_SPECIALIZATIONS add_rvalue_reference {
-  using type = __add_rvalue_reference_t<_Tp>;
+  using type _LIBCPP_NODEBUG = __add_rvalue_reference_t<_Tp>;
 };
 
 #if _LIBCPP_STD_VER >= 14
diff --git a/libcxx/include/__type_traits/common_reference.h b/libcxx/include/__type_traits/common_reference.h
index 0d35570da2622..c27da5251b9b7 100644
--- a/libcxx/include/__type_traits/common_reference.h
+++ b/libcxx/include/__type_traits/common_reference.h
@@ -121,7 +121,7 @@ struct common_reference<> {};
 // bullet 2 - sizeof...(T) == 1
 template <class _Tp>
 struct common_reference<_Tp> {
-  using type = _Tp;
+  using type _LIBCPP_NODEBUG = _Tp;
 };
 
 // bullet 3 - sizeof...(T) == 2
@@ -140,7 +140,7 @@ struct common_reference<_Tp, _Up> : __common_reference_sub_bullet1<_Tp, _Up> {};
 template <class _Tp, class _Up>
   requires is_reference_v<_Tp> && is_reference_v<_Up> && requires { typename __common_ref_t<_Tp, _Up>; }
 struct __common_reference_sub_bullet1<_Tp, _Up> {
-  using type = __common_ref_t<_Tp, _Up>;
+  using type _LIBCPP_NODEBUG = __common_ref_t<_Tp, _Up>;
 };
 
 // sub-bullet 2 - Otherwise, if basic_common_reference<remove_cvref_t<T1>, remove_cvref_t<T2>, XREF(T1), XREF(T2)>::type
@@ -158,7 +158,7 @@ using __basic_common_reference_t _LIBCPP_NODEBUG =
 template <class _Tp, class _Up>
   requires requires { typename __basic_common_reference_t<_Tp, _Up>; }
 struct __common_reference_sub_bullet2<_Tp, _Up> {
-  using type = __basic_common_reference_t<_Tp, _Up>;
+  using type _LIBCPP_NODEBUG = __basic_common_reference_t<_Tp, _Up>;
 };
 
 // sub-bullet 3 - Otherwise, if COND-RES(T1, T2) is well-formed,
@@ -166,7 +166,7 @@ struct __common_reference_sub_bullet2<_Tp, _Up> {
 template <class _Tp, class _Up>
   requires requires { typename __cond_res<_Tp, _Up>; }
 struct __common_reference_sub_bullet3<_Tp, _Up> {
-  using type = __cond_res<_Tp, _Up>;
+  using type _LIBCPP_NODEBUG = __cond_res<_Tp, _Up>;
 };
 
 // sub-bullet 4 & 5 - Otherwise, if common_type_t<T1, T2> is well-formed,
diff --git a/libcxx/include/__type_traits/common_type.h b/libcxx/include/__type_traits/common_type.h
index e4c6b495c3bda..4288cf50919ce 100644
--- a/libcxx/include/__type_traits/common_type.h
+++ b/libcxx/include/__type_traits/common_type.h
@@ -48,7 +48,7 @@ struct __common_type3 {};
 // sub-bullet 4 - "if COND_RES(CREF(D1), CREF(D2)) denotes a type..."
 template <class _Tp, class _Up>
 struct __common_type3<_Tp, _Up, void_t<__cond_type<const _Tp&, const _Up&>>> {
-  using type = remove_cvref_t<__cond_type<const _Tp&, const _Up&>>;
+  using type _LIBCPP_NODEBUG = remove_cvref_t<__cond_type<const _Tp&, const _Up&>>;
 };
 
 template <class _Tp, class _Up, class = void>
diff --git a/libcxx/include/__type_traits/strip_signature.h b/libcxx/include/__type_traits/strip_signature.h
index 3fe79592f55b8..c8b33278737ed 100644
--- a/libcxx/include/__type_traits/strip_signature.h
+++ b/libcxx/include/__type_traits/strip_signature.h
@@ -26,52 +26,52 @@ struct __strip_signature;
 
 template <class _Rp, class... _Args>
 struct __strip_signature<_Rp (*)(_Args...)> {
-  using type = _Rp(_Args...);
+  using type _LIBCPP_NODEBUG = _Rp(_Args...);
 };
 
 template <class _Rp, class... _Args>
 struct __strip_signature<_Rp (*)(_Args...) noexcept> {
-  using type = _Rp(_Args...);
+  using type _LIBCPP_NODEBUG = _Rp(_Args...);
 };
 
 #  endif // defined(__cpp_static_call_operator) && __cpp_static_call_operator >= 202207L
 
 // clang-format off
 template<class _Rp, class _Gp, class ..._Ap>
-struct __strip_signature<_Rp (_Gp::*) (_Ap...)> { using type = _Rp(_Ap...); };
+struct __strip_signature<_Rp (_Gp::*) (_Ap...)> { using type _LIBCPP_NODEBUG = _Rp(_Ap...); };
 template<class _Rp, class _Gp, class ..._Ap>
-struct __strip_signature<_Rp (_Gp::*) (_Ap...) const> { using type = _Rp(_Ap...); };
+struct __strip_signature<_Rp (_Gp::*) (_Ap...) const> { using type _LIBCPP_NODEBUG = _Rp(_Ap...); };
 template<class _Rp, class _Gp, class ..._Ap>
-struct __strip_signature<_Rp (_Gp::*) (_Ap...) volatile> { using type = _Rp(_Ap...); };
+struct __strip_signature<_Rp (_Gp::*) (_Ap...) volatile> { using type _LIBCPP_NODEBUG = _Rp(_Ap...); };
 template<class _Rp, class _Gp, class ..._Ap>
-struct __strip_signature<_Rp (_Gp::*) (_Ap...) const volatile> { using type = _Rp(_Ap...); };
+struct __strip_signature<_Rp (_Gp::*) (_Ap...) const volatile> { using type _LIBCPP_NODEBUG = _Rp(_Ap...); };
 
 template<class _Rp, class _Gp, class ..._Ap>
-struct __strip_signature<_Rp (_Gp::*) (_Ap...) &> { using type = _Rp(_Ap...); };
+struct __strip_signature<_Rp (_Gp::*) (_Ap...) &> { using type _LIBCPP_NODEBUG = _Rp(_Ap...); };
 template<class _Rp, class _Gp, class ..._Ap>
-struct __strip_signature<_Rp (_Gp::*) (_Ap...) const &> { using type = _Rp(_Ap...); };
+struct __strip_signature<_Rp (_Gp::*) (_Ap...) const &> { using type _LIBCPP_NODEBUG = _Rp(_Ap...); };
 template<class _Rp, class _Gp, class ..._Ap>
-struct __strip_signature<_Rp (_Gp::*) (_Ap...) volatile &> { using type = _Rp(_Ap...); };
+struct __strip_signature<_Rp (_Gp::*) (_Ap...) volatile &> { using type _LIBCPP_NODEBUG = _Rp(_Ap...); };
 template<class _Rp, class _Gp, class ..._Ap>
-struct __strip_signature<_Rp (_Gp::*) (_Ap...) const volatile &> { using type = _Rp(_Ap...); };
+struct __strip_signature<_Rp (_Gp::*) (_Ap...) const volatile &> { using type _LIBCPP_NODEBUG = _Rp(_Ap...); };
 
 template<class _Rp, class _Gp, class ..._Ap>
-struct __strip_signature<_Rp (_Gp::*) (_Ap...) noexcept> { using type = _Rp(_Ap...); };
+struct __strip_signature<_Rp (_Gp::*) (_Ap...) noexcept> { using type _LIBCPP_NODEBUG = _Rp(_Ap...); };
 template<class _Rp, class _Gp, class ..._Ap>
-struct __strip_signature<_Rp (_Gp::*) (_Ap...) const noexcept> { using type = _Rp(_Ap...); };
+struct __strip_signature<_Rp (_Gp::*) (_Ap...) const noexcept> { using type _LIBCPP_NODEBUG = _Rp(_Ap...); };
 template<class _Rp, class _Gp, class ..._Ap>
-struct __strip_signature<_Rp (_Gp::*) (_Ap...) volatile noexcept> { using type = _Rp(_Ap...); };
+struct __strip_signature<_Rp (_Gp::*) (_Ap...) volatile noexcept> { using type _LIBCPP_NODEBUG = _Rp(_Ap...); };
 template<class _Rp, class _Gp, class ..._Ap>
-struct __strip_signature<_Rp (_Gp::*) (_Ap...) const volatile noexcept> { using type = _Rp(_Ap...); };
+struct __strip_signature<_Rp (_Gp::*) (_Ap...) const volatile noexcept> { using type _LIBCPP_NODEBUG = _Rp(_Ap...); };
 
 template<class _Rp, class _Gp, class ..._Ap>
-struct __strip_signature<_Rp (_Gp::*) (_Ap...) & noexcept> { using type = _Rp(_Ap...); };
+struct __strip_signature<_Rp (_Gp::*) (_Ap...) & noexcept> { using type _LIBCPP_NODEBUG = _Rp(_Ap...); };
 template<class _Rp, class _Gp, class ..._Ap>
-struct __strip_signature<_Rp (_Gp::*) (_Ap...) const & noexcept> { using type = _Rp(_Ap...); };
+struct __strip_signature<_Rp (_Gp::*) (_Ap...) const & noexcept> { using type _LIBCPP_NODEBUG = _Rp(_Ap...); };
 template<class _Rp, class _Gp, class ..._Ap>
-struct __strip_signature<_Rp (_Gp::*) (_Ap...) volatile & noexcept> { using type = _Rp(_Ap...); };
+struct __strip_signature<_Rp (_Gp::*) (_Ap...) volatile & noexcept> { using type _LIBCPP_NODEBUG = _Rp(_Ap...); };
 template<class _Rp, class _Gp, class ..._Ap>
-struct __strip_signature<_Rp (_Gp::*) (_Ap...) const volatile & noexcept> { using type = _Rp(_Ap...); };
+struct __strip_signature<_Rp (_Gp::*) (_Ap...) const volatile & noexcept> { using type _LIBCPP_NODEBUG = _Rp(_Ap...); };
 // clang-format on
 
 _LIBCPP_END_NAMESPACE_STD
diff --git a/libcxx/include/__utility/pair.h b/libcxx/include/__utility/pair.h
index 7689ab2a48c6a..27a015477861c 100644
--- a/libcxx/include/__utility/pair.h
+++ b/libcxx/include/__utility/pair.h
@@ -506,13 +506,13 @@ template <class _T1, class _T2, class _U1, class _U2, template <class> class _TQ
     typename pair<common_reference_t<_TQual<_T1>, _UQual<_U1>>, common_reference_t<_TQual<_T2>, _UQual<_U2>>>;
   }
 struct basic_common_reference<pair<_T1, _T2>, pair<_U1, _U2>, _TQual, _UQual> {
-  using type = pair<common_reference_t<_TQual<_T1>, _UQual<_U1>>, common_reference_t<_TQual<_T2>, _UQual<_U2>>>;
+  using type _LIBCPP_NODEBUG = pair<common_reference_t<_TQual<_T1>, _UQual<_U1>>, common_reference_t<_TQual<_T2>, _UQual<_U2>>>;
 };
 
 template <class _T1, class _T2, class _U1, class _U2>
   requires requires { typename pair<common_type_t<_T1, _U1>, common_type_t<_T2, _U2>>; }
 struct common_type<pair<_T1, _T2>, pair<_U1, _U2>> {
-  using type = pair<common_type_t<_T1, _U1>, common_type_t<_T2, _U2>>;
+  using type _LIBCPP_NODEBUG = pair<common_type_t<_T1, _U1>, common_type_t<_T2, _U2>>;
 };
 #endif // _LIBCPP_STD_VER >= 23
 
diff --git a/libcxx/include/array b/libcxx/include/array
index 44c6bb5c5cc93..d536575d41680 100644
--- a/libcxx/include/array
+++ b/libcxx/include/array
@@ -497,7 +497,7 @@ struct _LIBCPP_TEMPLATE_VIS tuple_size<array<_Tp, _Size> > : public integral_con
 template <size_t _Ip, class _Tp, size_t _Size>
 struct _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, array<_Tp, _Size> > {
   static_assert(_Ip < _Size, "Index out of bounds in std::tuple_element<> (std::array)");
-  using type = _Tp;
+  using type _LIBCPP_NODEBUG = _Tp;
 };
 
 template <size_t _Ip, class _Tp, size_t _Size>
diff --git a/libcxx/include/complex b/libcxx/include/complex
index df18159595b34..5e1832e8009fd 100644
--- a/libcxx/include/complex
+++ b/libcxx/include/complex
@@ -1394,7 +1394,7 @@ struct tuple_size<complex<_Tp>> : integral_constant<size_t, 2> {};
 template <size_t _Ip, class _Tp>
 struct tuple_element<_Ip, complex<_Tp>> {
   static_assert(_Ip < 2, "Index value is out of range.");
-  using type = _Tp;
+  using type _LIBCPP_NODEBUG = _Tp;
 };
 
 template <size_t _Ip, class _Xp>
diff --git a/libcxx/include/experimental/__simd/declaration.h b/libcxx/include/experimental/__simd/declaration.h
index 1b4fcf958516c..d9395baecfe0f 100644
--- a/libcxx/include/experimental/__simd/declaration.h
+++ b/libcxx/include/experimental/__simd/declaration.h
@@ -49,7 +49,7 @@ using native = __vec_ext<_LIBCPP_NATIVE_SIMD_WIDTH_IN_BYTES / sizeof(_Tp)>;
 // TODO: make this platform dependent
 template <class _Tp, size_t _Np, class... _Abis>
 struct deduce {
-  using type = fixed_size<_Np>;
+  using type _LIBCPP_NODEBUG = fixed_size<_Np>;
 };
 
 // TODO: make this platform dependent
diff --git a/libcxx/include/tuple b/libcxx/include/tuple
index 5d968bfd4015a..d501509db28c2 100644
--- a/libcxx/include/tuple
+++ b/libcxx/include/tuple
@@ -1027,13 +1027,13 @@ public:
 template <class... _TTypes, class... _UTypes, template <class> class _TQual, template <class> class _UQual>
   requires requires { typename tuple<common_reference_t<_TQual<_TTypes>, _UQual<_UTypes>>...>; }
 struct basic_common_reference<tuple<_TTypes...>, tuple<_UTypes...>, _TQual, _UQual> {
-  using type = tuple<common_reference_t<_TQual<_TTypes>, _UQual<_UTypes>>...>;
+  using type _LIBCPP_NODEBUG = tuple<common_reference_t<_TQual<_TTypes>, _UQual<_UTypes>>...>;
 };
 
 template <class... _TTypes, class... _UTypes>
   requires requires { typename tuple<common_type_t<_TTypes, _UTypes>...>; }
 struct common_type<tuple<_TTypes...>, tuple<_UTypes...>> {
-  using type = tuple<common_type_t<_TTypes, _UTypes>...>;
+  using type _LIBCPP_NODEBUG = tuple<common_type_t<_TTypes, _UTypes>...>;
 };
 #    endif // _LIBCPP_STD_VER >= 23
 
diff --git a/libcxx/include/variant b/libcxx/include/variant
index 9e78ff2cc1a4f..38c34725d5e03 100644
--- a/libcxx/include/variant
+++ b/libcxx/include/variant
@@ -341,7 +341,7 @@ struct _LIBCPP_TEMPLATE_VIS variant_alternative<_Ip, const volatile _Tp> : add_c
 template <size_t _Ip, class... _Types>
 struct _LIBCPP_TEMPLATE_VIS variant_alternative<_Ip, variant<_Types...>> {
   static_assert(_Ip < sizeof...(_Types), "Index out of bounds in std::variant_alternative<>");
-  using type = __type_pack_element<_Ip, _Types...>;
+  using type _LIBCPP_NODEBUG = __type_pack_element<_Ip, _Types...>;
 };
 
 template <size_t _NumAlternatives>
diff --git a/libcxx/test/tools/clang_tidy_checks/nodebug_on_aliases.cpp b/libcxx/test/tools/clang_tidy_checks/nodebug_on_aliases.cpp
index 9b96269e59805..e28713e9a5ea3 100644
--- a/libcxx/test/tools/clang_tidy_checks/nodebug_on_aliases.cpp
+++ b/libcxx/test/tools/clang_tidy_checks/nodebug_on_aliases.cpp
@@ -14,6 +14,7 @@
 namespace libcpp {
 namespace {
 AST_MATCHER(clang::NamedDecl, isPretty) { return !is_ugly_name(Node.getName()); }
+AST_MATCHER(clang::NamedDecl, isUgly) { return is_ugly_name(Node.getName()); }
 } // namespace
 
 nodebug_on_aliases::nodebug_on_aliases(llvm::StringRef name, clang::tidy::ClangTidyContext* context)
@@ -25,11 +26,29 @@ void nodebug_on_aliases::registerMatchers(clang::ast_matchers::MatchFinder* find
       typeAliasDecl(unless(anyOf(isPretty(), hasAttr(clang::attr::NoDebug), hasAncestor(functionDecl()))))
           .bind("nodebug_on_internal_aliases"),
       this);
+
+  finder->addMatcher(
+      typeAliasDecl(
+          unless(hasAttr(clang::attr::NoDebug)),
+          hasName("type"),
+          hasAncestor(cxxRecordDecl(unless(has(namedDecl(unless(anyOf(
+              typeAliasDecl(hasName("type")),
+              typeAliasDecl(isUgly()),
+              recordDecl(isImplicit()),
+              templateTypeParmDecl(),
+              nonTypeTemplateParmDecl(),
+              templateTemplateParmDecl()))))))))
+          .bind("nodebug_on_type_traits"),
+      this);
 }
 
 void nodebug_on_aliases::check(const clang::ast_matchers::MatchFinder::MatchResult& result) {
   if (const auto* alias = result.Nodes.getNodeAs<clang::TypeAliasDecl>("nodebug_on_internal_aliases")) {
     diag(alias->getBeginLoc(), "Internal aliases should always be marked _LIBCPP_NODEBUG");
   }
+
+  if (const auto* alias = result.Nodes.getNodeAs<clang::TypeAliasDecl>("nodebug_on_type_traits")) {
+    diag(alias->getBeginLoc(), "The alias of type traits should always be marked _LIBCPP_NODEBUG");
+  }
 }
 } // namespace libcpp



More information about the libcxx-commits mailing list