Skip to content

Commit fb44f00

Browse files
authored
[libc++] Add [[gnu::nodebug]] on type traits (#128502)
1 parent 4781a8e commit fb44f00

28 files changed

+115
-90
lines changed

libcxx/docs/CodingGuidelines.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ Library-internal type aliases should be annotated with ``_LIBCPP_NODEBUG``
191191
Libc++ has lots of internal type aliases. Accumulated, these can result in significant amounts of debug information that
192192
users generally don't care about, since users don't try to debug standard library facilities in most cases. For that
193193
reason, all library-internal type aliases that aren't function-local should be annotated with ``_LIBCPP_NODEBUG`` to
194-
prevent compilers from generating said debug information.
194+
prevent compilers from generating said debug information. Aliases inside type traits (i.e. aliases named ``type``)
195+
should be annotated for the same reason.
195196

196197
This is enforced by the clang-tidy check ``libcpp-nodebug-on-aliases``.

libcxx/include/__algorithm/simd_utils.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,20 +51,20 @@ struct __get_as_integer_type_impl;
5151

5252
template <>
5353
struct __get_as_integer_type_impl<1> {
54-
using type = uint8_t;
54+
using type _LIBCPP_NODEBUG = uint8_t;
5555
};
5656

5757
template <>
5858
struct __get_as_integer_type_impl<2> {
59-
using type = uint16_t;
59+
using type _LIBCPP_NODEBUG = uint16_t;
6060
};
6161
template <>
6262
struct __get_as_integer_type_impl<4> {
63-
using type = uint32_t;
63+
using type _LIBCPP_NODEBUG = uint32_t;
6464
};
6565
template <>
6666
struct __get_as_integer_type_impl<8> {
67-
using type = uint64_t;
67+
using type _LIBCPP_NODEBUG = uint64_t;
6868
};
6969

7070
template <class _Tp>

libcxx/include/__compare/common_comparison_category.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ _LIBCPP_HIDE_FROM_ABI constexpr auto __get_comp_type() {
7373
// [cmp.common], common comparison category type
7474
template <class... _Ts>
7575
struct _LIBCPP_TEMPLATE_VIS common_comparison_category {
76-
using type = decltype(__comp_detail::__get_comp_type<_Ts...>());
76+
using type _LIBCPP_NODEBUG = decltype(__comp_detail::__get_comp_type<_Ts...>());
7777
};
7878

7979
template <class... _Ts>

libcxx/include/__compare/compare_three_way_result.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ struct _LIBCPP_HIDE_FROM_ABI __compare_three_way_result<
2929
_Tp,
3030
_Up,
3131
decltype(std::declval<__make_const_lvalue_ref<_Tp>>() <=> std::declval<__make_const_lvalue_ref<_Up>>(), void())> {
32-
using type = decltype(std::declval<__make_const_lvalue_ref<_Tp>>() <=> std::declval<__make_const_lvalue_ref<_Up>>());
32+
using type _LIBCPP_NODEBUG =
33+
decltype(std::declval<__make_const_lvalue_ref<_Tp>>() <=> std::declval<__make_const_lvalue_ref<_Up>>());
3334
};
3435

3536
template <class _Tp, class _Up = _Tp>

libcxx/include/__functional/bind.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ struct __mu_return_invokable // false
130130

131131
template <class _Ti, class... _Uj>
132132
struct __mu_return_invokable<true, _Ti, _Uj...> {
133-
using type = __invoke_result_t<_Ti&, _Uj...>;
133+
using type _LIBCPP_NODEBUG = __invoke_result_t<_Ti&, _Uj...>;
134134
};
135135

136136
template <class _Ti, class... _Uj>
@@ -181,12 +181,12 @@ struct __bind_return;
181181

182182
template <class _Fp, class... _BoundArgs, class _TupleUj>
183183
struct __bind_return<_Fp, tuple<_BoundArgs...>, _TupleUj, true> {
184-
using type = __invoke_result_t< _Fp&, typename __mu_return< _BoundArgs, _TupleUj >::type... >;
184+
using type _LIBCPP_NODEBUG = __invoke_result_t<_Fp&, typename __mu_return<_BoundArgs, _TupleUj>::type...>;
185185
};
186186

187187
template <class _Fp, class... _BoundArgs, class _TupleUj>
188188
struct __bind_return<_Fp, const tuple<_BoundArgs...>, _TupleUj, true> {
189-
using type = __invoke_result_t< _Fp&, typename __mu_return< const _BoundArgs, _TupleUj >::type... >;
189+
using type _LIBCPP_NODEBUG = __invoke_result_t<_Fp&, typename __mu_return<const _BoundArgs, _TupleUj>::type...>;
190190
};
191191

192192
template <class _Fp, class _BoundArgs, size_t... _Indx, class _Args>

libcxx/include/__iterator/common_iterator.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,13 +272,13 @@ concept __common_iter_has_ptr_op = requires(const common_iterator<_Iter, _Sent>&
272272

273273
template <class, class>
274274
struct __arrow_type_or_void {
275-
using type = void;
275+
using type _LIBCPP_NODEBUG = void;
276276
};
277277

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

284284
template <input_iterator _Iter, class _Sent>

libcxx/include/__iterator/concepts.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,13 @@ concept __specialization_of_projected = requires {
8080

8181
template <class _Tp>
8282
struct __indirect_value_t_impl {
83-
using type = iter_value_t<_Tp>&;
83+
using type _LIBCPP_NODEBUG = iter_value_t<_Tp>&;
8484
};
8585
template <__specialization_of_projected _Tp>
8686
struct __indirect_value_t_impl<_Tp> {
87-
using type = invoke_result_t<__projected_projection_t<_Tp>&,
88-
typename __indirect_value_t_impl<__projected_iterator_t<_Tp>>::type>;
87+
using type _LIBCPP_NODEBUG =
88+
invoke_result_t<__projected_projection_t<_Tp>&,
89+
typename __indirect_value_t_impl<__projected_iterator_t<_Tp>>::type>;
8990
};
9091

9192
template <indirectly_readable _Tp>

libcxx/include/__iterator/iterator_traits.h

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ struct _LIBCPP_TEMPLATE_VIS contiguous_iterator_tag : public random_access_itera
7777

7878
template <class _Iter>
7979
struct __iter_traits_cache {
80-
using type = _If< __is_primary_template<iterator_traits<_Iter> >::value, _Iter, iterator_traits<_Iter> >;
80+
using type _LIBCPP_NODEBUG =
81+
_If<__is_primary_template<iterator_traits<_Iter> >::value, _Iter, iterator_traits<_Iter> >;
8182
};
8283
template <class _Iter>
8384
using _ITER_TRAITS _LIBCPP_NODEBUG = typename __iter_traits_cache<_Iter>::type;
@@ -101,9 +102,10 @@ struct __test_iter_concept : _IsValidExpansion<_Tester::template _Apply, _Iter>,
101102

102103
template <class _Iter>
103104
struct __iter_concept_cache {
104-
using type = _Or< __test_iter_concept<_Iter, __iter_concept_concept_test>,
105-
__test_iter_concept<_Iter, __iter_concept_category_test>,
106-
__test_iter_concept<_Iter, __iter_concept_random_fallback> >;
105+
using type _LIBCPP_NODEBUG =
106+
_Or<__test_iter_concept<_Iter, __iter_concept_concept_test>,
107+
__test_iter_concept<_Iter, __iter_concept_category_test>,
108+
__test_iter_concept<_Iter, __iter_concept_random_fallback> >;
107109
};
108110

109111
template <class _Iter>
@@ -221,12 +223,12 @@ concept __specifies_members = requires {
221223

222224
template <class>
223225
struct __iterator_traits_member_pointer_or_void {
224-
using type = void;
226+
using type _LIBCPP_NODEBUG = void;
225227
};
226228

227229
template <__has_member_pointer _Tp>
228230
struct __iterator_traits_member_pointer_or_void<_Tp> {
229-
using type = typename _Tp::pointer;
231+
using type _LIBCPP_NODEBUG = typename _Tp::pointer;
230232
};
231233

232234
template <class _Tp>
@@ -239,63 +241,63 @@ concept __cpp17_input_iterator_missing_members =
239241
// Otherwise, `pointer` names `void`.
240242
template <class>
241243
struct __iterator_traits_member_pointer_or_arrow_or_void {
242-
using type = void;
244+
using type _LIBCPP_NODEBUG = void;
243245
};
244246

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

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

260262
// Otherwise, `reference` names `iter-reference-t<I>`.
261263
template <class _Ip>
262264
struct __iterator_traits_member_reference {
263-
using type = iter_reference_t<_Ip>;
265+
using type _LIBCPP_NODEBUG = iter_reference_t<_Ip>;
264266
};
265267

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

273275
// [iterator.traits]/3.2.3.4
274276
// input_iterator_tag
275277
template <class _Ip>
276278
struct __deduce_iterator_category {
277-
using type = input_iterator_tag;
279+
using type _LIBCPP_NODEBUG = input_iterator_tag;
278280
};
279281

280282
// [iterator.traits]/3.2.3.1
281283
// `random_access_iterator_tag` if `I` satisfies `cpp17-random-access-iterator`, or otherwise
282284
template <__iterator_traits_detail::__cpp17_random_access_iterator _Ip>
283285
struct __deduce_iterator_category<_Ip> {
284-
using type = random_access_iterator_tag;
286+
using type _LIBCPP_NODEBUG = random_access_iterator_tag;
285287
};
286288

287289
// [iterator.traits]/3.2.3.2
288290
// `bidirectional_iterator_tag` if `I` satisfies `cpp17-bidirectional-iterator`, or otherwise
289291
template <__iterator_traits_detail::__cpp17_bidirectional_iterator _Ip>
290292
struct __deduce_iterator_category<_Ip> {
291-
using type = bidirectional_iterator_tag;
293+
using type _LIBCPP_NODEBUG = bidirectional_iterator_tag;
292294
};
293295

294296
// [iterator.traits]/3.2.3.3
295297
// `forward_iterator_tag` if `I` satisfies `cpp17-forward-iterator`, or otherwise
296298
template <__iterator_traits_detail::__cpp17_forward_iterator _Ip>
297299
struct __deduce_iterator_category<_Ip> {
298-
using type = forward_iterator_tag;
300+
using type _LIBCPP_NODEBUG = forward_iterator_tag;
299301
};
300302

301303
template <class _Ip>
@@ -306,21 +308,21 @@ struct __iterator_traits_iterator_category : __deduce_iterator_category<_Ip> {};
306308
// that type.
307309
template <__has_member_iterator_category _Ip>
308310
struct __iterator_traits_iterator_category<_Ip> {
309-
using type = typename _Ip::iterator_category;
311+
using type _LIBCPP_NODEBUG = typename _Ip::iterator_category;
310312
};
311313

312314
// otherwise, it names void.
313315
template <class>
314316
struct __iterator_traits_difference_type {
315-
using type = void;
317+
using type _LIBCPP_NODEBUG = void;
316318
};
317319

318320
// If the qualified-id `incrementable_traits<I>::difference_type` is valid and denotes a type, then
319321
// `difference_type` names that type;
320322
template <class _Ip>
321323
requires requires { typename incrementable_traits<_Ip>::difference_type; }
322324
struct __iterator_traits_difference_type<_Ip> {
323-
using type = typename incrementable_traits<_Ip>::difference_type;
325+
using type _LIBCPP_NODEBUG = typename incrementable_traits<_Ip>::difference_type;
324326
};
325327

326328
// [iterator.traits]/3.4

libcxx/include/__mdspan/extents.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -440,13 +440,13 @@ struct __make_dextents;
440440

441441
template <class _IndexType, size_t _Rank, size_t... _ExtentsPack>
442442
struct __make_dextents< _IndexType, _Rank, extents<_IndexType, _ExtentsPack...>> {
443-
using type =
443+
using type _LIBCPP_NODEBUG =
444444
typename __make_dextents< _IndexType, _Rank - 1, extents<_IndexType, dynamic_extent, _ExtentsPack...>>::type;
445445
};
446446

447447
template <class _IndexType, size_t... _ExtentsPack>
448448
struct __make_dextents< _IndexType, 0, extents<_IndexType, _ExtentsPack...>> {
449-
using type = extents<_IndexType, _ExtentsPack...>;
449+
using type _LIBCPP_NODEBUG = extents<_IndexType, _ExtentsPack...>;
450450
};
451451

452452
} // namespace __mdspan_detail

libcxx/include/__memory/pointer_traits.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -259,20 +259,20 @@ struct __pointer_of {};
259259
template <class _Tp>
260260
requires(__has_pointer<_Tp>::value)
261261
struct __pointer_of<_Tp> {
262-
using type = typename _Tp::pointer;
262+
using type _LIBCPP_NODEBUG = typename _Tp::pointer;
263263
};
264264

265265
template <class _Tp>
266266
requires(!__has_pointer<_Tp>::value && __has_element_type<_Tp>::value)
267267
struct __pointer_of<_Tp> {
268-
using type = typename _Tp::element_type*;
268+
using type _LIBCPP_NODEBUG = typename _Tp::element_type*;
269269
};
270270

271271
template <class _Tp>
272272
requires(!__has_pointer<_Tp>::value && !__has_element_type<_Tp>::value &&
273273
__has_element_type<pointer_traits<_Tp>>::value)
274274
struct __pointer_of<_Tp> {
275-
using type = typename pointer_traits<_Tp>::element_type*;
275+
using type _LIBCPP_NODEBUG = typename pointer_traits<_Tp>::element_type*;
276276
};
277277

278278
template <typename _Tp>

libcxx/include/__ranges/drop_view.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -185,22 +185,22 @@ struct __passthrough_type;
185185

186186
template <class _Tp, size_t _Extent>
187187
struct __passthrough_type<span<_Tp, _Extent>> {
188-
using type = span<_Tp>;
188+
using type _LIBCPP_NODEBUG = span<_Tp>;
189189
};
190190

191191
template <class _CharT, class _Traits>
192192
struct __passthrough_type<basic_string_view<_CharT, _Traits>> {
193-
using type = basic_string_view<_CharT, _Traits>;
193+
using type _LIBCPP_NODEBUG = basic_string_view<_CharT, _Traits>;
194194
};
195195

196196
template <class _Np, class _Bound>
197197
struct __passthrough_type<iota_view<_Np, _Bound>> {
198-
using type = iota_view<_Np, _Bound>;
198+
using type _LIBCPP_NODEBUG = iota_view<_Np, _Bound>;
199199
};
200200

201201
template <class _Iter, class _Sent, subrange_kind _Kind>
202202
struct __passthrough_type<subrange<_Iter, _Sent, _Kind>> {
203-
using type = subrange<_Iter, _Sent, _Kind>;
203+
using type _LIBCPP_NODEBUG = subrange<_Iter, _Sent, _Kind>;
204204
};
205205

206206
template <class _Tp>

libcxx/include/__ranges/repeat_view.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,12 @@ concept __integer_like_with_usable_difference_type =
5252

5353
template <class _Tp>
5454
struct __repeat_view_iterator_difference {
55-
using type = _IotaDiffT<_Tp>;
55+
using type _LIBCPP_NODEBUG = _IotaDiffT<_Tp>;
5656
};
5757

5858
template <__signed_integer_like _Tp>
5959
struct __repeat_view_iterator_difference<_Tp> {
60-
using type = _Tp;
60+
using type _LIBCPP_NODEBUG = _Tp;
6161
};
6262

6363
template <class _Tp>

libcxx/include/__ranges/reverse_view.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,13 +144,13 @@ inline constexpr bool __is_unsized_reverse_subrange<subrange<reverse_iterator<_I
144144

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

151151
template <class _Iter, subrange_kind _Kind>
152152
struct __unwrapped_reverse_subrange<subrange<reverse_iterator<_Iter>, reverse_iterator<_Iter>, _Kind>> {
153-
using type = subrange<_Iter, _Iter, _Kind>;
153+
using type _LIBCPP_NODEBUG = subrange<_Iter, _Iter, _Kind>;
154154
};
155155

156156
struct __fn : __range_adaptor_closure<__fn> {

libcxx/include/__ranges/subrange.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -247,22 +247,22 @@ struct tuple_size<ranges::subrange<_Ip, _Sp, _Kp>> : integral_constant<size_t, 2
247247

248248
template <class _Ip, class _Sp, ranges::subrange_kind _Kp>
249249
struct tuple_element<0, ranges::subrange<_Ip, _Sp, _Kp>> {
250-
using type = _Ip;
250+
using type _LIBCPP_NODEBUG = _Ip;
251251
};
252252

253253
template <class _Ip, class _Sp, ranges::subrange_kind _Kp>
254254
struct tuple_element<1, ranges::subrange<_Ip, _Sp, _Kp>> {
255-
using type = _Sp;
255+
using type _LIBCPP_NODEBUG = _Sp;
256256
};
257257

258258
template <class _Ip, class _Sp, ranges::subrange_kind _Kp>
259259
struct tuple_element<0, const ranges::subrange<_Ip, _Sp, _Kp>> {
260-
using type = _Ip;
260+
using type _LIBCPP_NODEBUG = _Ip;
261261
};
262262

263263
template <class _Ip, class _Sp, ranges::subrange_kind _Kp>
264264
struct tuple_element<1, const ranges::subrange<_Ip, _Sp, _Kp>> {
265-
using type = _Sp;
265+
using type _LIBCPP_NODEBUG = _Sp;
266266
};
267267

268268
#endif // _LIBCPP_STD_VER >= 20

libcxx/include/__ranges/take_view.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,18 +229,18 @@ struct __passthrough_type;
229229

230230
template <class _Tp, size_t _Extent>
231231
struct __passthrough_type<span<_Tp, _Extent>> {
232-
using type = span<_Tp>;
232+
using type _LIBCPP_NODEBUG = span<_Tp>;
233233
};
234234

235235
template <class _CharT, class _Traits>
236236
struct __passthrough_type<basic_string_view<_CharT, _Traits>> {
237-
using type = basic_string_view<_CharT, _Traits>;
237+
using type _LIBCPP_NODEBUG = basic_string_view<_CharT, _Traits>;
238238
};
239239

240240
template <class _Iter, class _Sent, subrange_kind _Kind>
241241
requires requires { typename subrange<_Iter>; }
242242
struct __passthrough_type<subrange<_Iter, _Sent, _Kind>> {
243-
using type = subrange<_Iter>;
243+
using type _LIBCPP_NODEBUG = subrange<_Iter>;
244244
};
245245

246246
template <class _Tp>

0 commit comments

Comments
 (0)