Skip to content

Commit 1e24b4d

Browse files
committed
[libc++] Fix template parameter naming and enforce it through readability-identifier-naming
Reviewed By: #libc, Mordante Spies: Mordante, aheejin, libcxx-commits Differential Revision: https://reviews.llvm.org/D156059
1 parent 3326feb commit 1e24b4d

20 files changed

+148
-139
lines changed

libcxx/.clang-tidy

+8
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,14 @@ CheckOptions:
5050
value: lower_case
5151
- key: readability-identifier-naming.LocalVariablePrefix
5252
value: __
53+
- key: readability-identifier-naming.TemplateParameterCase
54+
value: CamelCase
55+
- key: readability-identifier-naming.TemplateParameterPrefix
56+
value: _
57+
- key: readability-identifier-naming.TemplateParameterIgnoredRegexp
58+
value: (.*\:auto|expr-type) # This is https://llvm.org/PR56464
59+
- key: readability-identifier-naming.ValueTemplateParameterIgnoredRegexp # TODO: enforce naming of variable parameters
60+
value: .*
5361

5462
# TODO: investigate these checks
5563
# bugprone-branch-clone,

libcxx/include/__bit_reference

+23-23
Original file line numberDiff line numberDiff line change
@@ -731,12 +731,12 @@ move_backward(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsCons
731731

732732
// swap_ranges
733733

734-
template <class __C1, class __C2>
735-
_LIBCPP_HIDE_FROM_ABI __bit_iterator<__C2, false>
736-
__swap_ranges_aligned(__bit_iterator<__C1, false> __first, __bit_iterator<__C1, false> __last,
737-
__bit_iterator<__C2, false> __result)
734+
template <class _Cl, class _Cr>
735+
_LIBCPP_HIDE_FROM_ABI __bit_iterator<_Cr, false>
736+
__swap_ranges_aligned(__bit_iterator<_Cl, false> __first, __bit_iterator<_Cl, false> __last,
737+
__bit_iterator<_Cr, false> __result)
738738
{
739-
typedef __bit_iterator<__C1, false> _I1;
739+
typedef __bit_iterator<_Cl, false> _I1;
740740
typedef typename _I1::difference_type difference_type;
741741
typedef typename _I1::__storage_type __storage_type;
742742
const int __bits_per_word = _I1::__bits_per_word;
@@ -781,12 +781,12 @@ __swap_ranges_aligned(__bit_iterator<__C1, false> __first, __bit_iterator<__C1,
781781
return __result;
782782
}
783783

784-
template <class __C1, class __C2>
785-
_LIBCPP_HIDE_FROM_ABI __bit_iterator<__C2, false>
786-
__swap_ranges_unaligned(__bit_iterator<__C1, false> __first, __bit_iterator<__C1, false> __last,
787-
__bit_iterator<__C2, false> __result)
784+
template <class _Cl, class _Cr>
785+
_LIBCPP_HIDE_FROM_ABI __bit_iterator<_Cr, false>
786+
__swap_ranges_unaligned(__bit_iterator<_Cl, false> __first, __bit_iterator<_Cl, false> __last,
787+
__bit_iterator<_Cr, false> __result)
788788
{
789-
typedef __bit_iterator<__C1, false> _I1;
789+
typedef __bit_iterator<_Cl, false> _I1;
790790
typedef typename _I1::difference_type difference_type;
791791
typedef typename _I1::__storage_type __storage_type;
792792
const int __bits_per_word = _I1::__bits_per_word;
@@ -881,11 +881,11 @@ __swap_ranges_unaligned(__bit_iterator<__C1, false> __first, __bit_iterator<__C1
881881
return __result;
882882
}
883883

884-
template <class __C1, class __C2>
884+
template <class _Cl, class _Cr>
885885
inline _LIBCPP_INLINE_VISIBILITY
886-
__bit_iterator<__C2, false>
887-
swap_ranges(__bit_iterator<__C1, false> __first1, __bit_iterator<__C1, false> __last1,
888-
__bit_iterator<__C2, false> __first2)
886+
__bit_iterator<_Cr, false>
887+
swap_ranges(__bit_iterator<_Cl, false> __first1, __bit_iterator<_Cl, false> __last1,
888+
__bit_iterator<_Cr, false> __first2)
889889
{
890890
if (__first1.__ctz_ == __first2.__ctz_)
891891
return _VSTD::__swap_ranges_aligned(__first1, __last1, __first2);
@@ -1314,15 +1314,15 @@ private:
13141314
friend __bit_iterator<_Dp, false> copy_backward(__bit_iterator<_Dp, _IC> __first,
13151315
__bit_iterator<_Dp, _IC> __last,
13161316
__bit_iterator<_Dp, false> __result);
1317-
template <class __C1, class __C2>friend __bit_iterator<__C2, false> __swap_ranges_aligned(__bit_iterator<__C1, false>,
1318-
__bit_iterator<__C1, false>,
1319-
__bit_iterator<__C2, false>);
1320-
template <class __C1, class __C2>friend __bit_iterator<__C2, false> __swap_ranges_unaligned(__bit_iterator<__C1, false>,
1321-
__bit_iterator<__C1, false>,
1322-
__bit_iterator<__C2, false>);
1323-
template <class __C1, class __C2>friend __bit_iterator<__C2, false> swap_ranges(__bit_iterator<__C1, false>,
1324-
__bit_iterator<__C1, false>,
1325-
__bit_iterator<__C2, false>);
1317+
template <class _Cl, class _Cr>friend __bit_iterator<_Cr, false> __swap_ranges_aligned(__bit_iterator<_Cl, false>,
1318+
__bit_iterator<_Cl, false>,
1319+
__bit_iterator<_Cr, false>);
1320+
template <class _Cl, class _Cr>friend __bit_iterator<_Cr, false> __swap_ranges_unaligned(__bit_iterator<_Cl, false>,
1321+
__bit_iterator<_Cl, false>,
1322+
__bit_iterator<_Cr, false>);
1323+
template <class _Cl, class _Cr>friend __bit_iterator<_Cr, false> swap_ranges(__bit_iterator<_Cl, false>,
1324+
__bit_iterator<_Cl, false>,
1325+
__bit_iterator<_Cr, false>);
13261326
template <class _Dp>
13271327
_LIBCPP_CONSTEXPR_SINCE_CXX20
13281328
friend __bit_iterator<_Dp, false> rotate(__bit_iterator<_Dp, false>,

libcxx/include/__chrono/calendar.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ namespace chrono
2626
{
2727

2828
struct local_t {};
29-
template<class Duration>
30-
using local_time = time_point<local_t, Duration>;
29+
template<class _Duration>
30+
using local_time = time_point<local_t, _Duration>;
3131
using local_seconds = local_time<seconds>;
3232
using local_days = local_time<days>;
3333

libcxx/include/__format/format_context.h

+6-6
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,9 @@ class
120120
// TODO FMT Validate whether lazy creation is the best solution.
121121
optional<_VSTD::locale> __loc_;
122122

123-
template <class __OutIt, class __CharT>
124-
friend _LIBCPP_HIDE_FROM_ABI basic_format_context<__OutIt, __CharT>
125-
__format_context_create(__OutIt, basic_format_args<basic_format_context<__OutIt, __CharT>>,
123+
template <class _OtherOutIt, class _OtherCharT>
124+
friend _LIBCPP_HIDE_FROM_ABI basic_format_context<_OtherOutIt, _OtherCharT>
125+
__format_context_create(_OtherOutIt, basic_format_args<basic_format_context<_OtherOutIt, _OtherCharT>>,
126126
optional<_VSTD::locale>&&);
127127

128128
// Note: the Standard doesn't specify the required constructors.
@@ -133,9 +133,9 @@ class
133133
: __out_it_(_VSTD::move(__out_it)), __args_(__args),
134134
__loc_(_VSTD::move(__loc)) {}
135135
#else
136-
template <class __OutIt, class __CharT>
137-
friend _LIBCPP_HIDE_FROM_ABI basic_format_context<__OutIt, __CharT>
138-
__format_context_create(__OutIt, basic_format_args<basic_format_context<__OutIt, __CharT>>);
136+
template <class _OtherOutIt, class _OtherCharT>
137+
friend _LIBCPP_HIDE_FROM_ABI basic_format_context<_OtherOutIt, _OtherCharT>
138+
__format_context_create(_OtherOutIt, basic_format_args<basic_format_context<_OtherOutIt, _OtherCharT>>);
139139

140140
_LIBCPP_HIDE_FROM_ABI
141141
explicit basic_format_context(_OutIt __out_it,

libcxx/include/__format/range_default_formatter.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,9 @@ struct _LIBCPP_TEMPLATE_VIS __range_default_formatter<range_format::sequence, _R
111111
return __underlying_.parse(__ctx);
112112
}
113113

114-
template <class FormatContext>
115-
_LIBCPP_HIDE_FROM_ABI typename FormatContext::iterator format(__maybe_const_r& __range, FormatContext& __ctx) const {
114+
template <class _FormatContext>
115+
_LIBCPP_HIDE_FROM_ABI typename _FormatContext::iterator
116+
format(__maybe_const_r& __range, _FormatContext& __ctx) const {
116117
return __underlying_.format(__range, __ctx);
117118
}
118119
};

libcxx/include/__functional/binder1st.h

+14-14
Original file line numberDiff line numberDiff line change
@@ -21,30 +21,30 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2121

2222
#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_BINDERS)
2323

24-
template <class __Operation>
24+
template <class _Operation>
2525
class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 binder1st
26-
: public __unary_function<typename __Operation::second_argument_type, typename __Operation::result_type>
26+
: public __unary_function<typename _Operation::second_argument_type, typename _Operation::result_type>
2727
{
2828
protected:
29-
__Operation op;
30-
typename __Operation::first_argument_type value;
29+
_Operation op;
30+
typename _Operation::first_argument_type value;
3131
public:
32-
_LIBCPP_INLINE_VISIBILITY binder1st(const __Operation& __x,
33-
const typename __Operation::first_argument_type __y)
32+
_LIBCPP_INLINE_VISIBILITY binder1st(const _Operation& __x,
33+
const typename _Operation::first_argument_type __y)
3434
: op(__x), value(__y) {}
35-
_LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
36-
(typename __Operation::second_argument_type& __x) const
35+
_LIBCPP_INLINE_VISIBILITY typename _Operation::result_type operator()
36+
(typename _Operation::second_argument_type& __x) const
3737
{return op(value, __x);}
38-
_LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
39-
(const typename __Operation::second_argument_type& __x) const
38+
_LIBCPP_INLINE_VISIBILITY typename _Operation::result_type operator()
39+
(const typename _Operation::second_argument_type& __x) const
4040
{return op(value, __x);}
4141
};
4242

43-
template <class __Operation, class _Tp>
43+
template <class _Operation, class _Tp>
4444
_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY
45-
binder1st<__Operation>
46-
bind1st(const __Operation& __op, const _Tp& __x)
47-
{return binder1st<__Operation>(__op, __x);}
45+
binder1st<_Operation>
46+
bind1st(const _Operation& __op, const _Tp& __x)
47+
{return binder1st<_Operation>(__op, __x);}
4848

4949
#endif // _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_BINDERS)
5050

libcxx/include/__functional/binder2nd.h

+13-13
Original file line numberDiff line numberDiff line change
@@ -21,30 +21,30 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2121

2222
#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_BINDERS)
2323

24-
template <class __Operation>
24+
template <class _Operation>
2525
class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 binder2nd
26-
: public __unary_function<typename __Operation::first_argument_type, typename __Operation::result_type>
26+
: public __unary_function<typename _Operation::first_argument_type, typename _Operation::result_type>
2727
{
2828
protected:
29-
__Operation op;
30-
typename __Operation::second_argument_type value;
29+
_Operation op;
30+
typename _Operation::second_argument_type value;
3131
public:
3232
_LIBCPP_INLINE_VISIBILITY
33-
binder2nd(const __Operation& __x, const typename __Operation::second_argument_type __y)
33+
binder2nd(const _Operation& __x, const typename _Operation::second_argument_type __y)
3434
: op(__x), value(__y) {}
35-
_LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
36-
( typename __Operation::first_argument_type& __x) const
35+
_LIBCPP_INLINE_VISIBILITY typename _Operation::result_type operator()
36+
( typename _Operation::first_argument_type& __x) const
3737
{return op(__x, value);}
38-
_LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
39-
(const typename __Operation::first_argument_type& __x) const
38+
_LIBCPP_INLINE_VISIBILITY typename _Operation::result_type operator()
39+
(const typename _Operation::first_argument_type& __x) const
4040
{return op(__x, value);}
4141
};
4242

43-
template <class __Operation, class _Tp>
43+
template <class _Operation, class _Tp>
4444
_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY
45-
binder2nd<__Operation>
46-
bind2nd(const __Operation& __op, const _Tp& __x)
47-
{return binder2nd<__Operation>(__op, __x);}
45+
binder2nd<_Operation>
46+
bind2nd(const _Operation& __op, const _Tp& __x)
47+
{return binder2nd<_Operation>(__op, __x);}
4848

4949
#endif // _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_BINDERS)
5050

libcxx/include/__fwd/mdspan.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@ _LIBCPP_BEGIN_NAMESPACE_STD
3232

3333
// Layout policy with a mapping which corresponds to FORTRAN-style array layouts
3434
struct layout_left {
35-
template <class Extents>
35+
template <class _Extents>
3636
class mapping;
3737
};
3838

3939
// Layout policy with a mapping which corresponds to C-style array layouts
4040
struct layout_right {
41-
template <class Extents>
41+
template <class _Extents>
4242
class mapping;
4343
};
4444

libcxx/include/__stop_token/stop_callback.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ class _LIBCPP_AVAILABILITY_SYNC stop_callback : private __stop_callback_base {
8989
}
9090
};
9191

92-
template <class Callback>
93-
_LIBCPP_AVAILABILITY_SYNC stop_callback(stop_token, Callback) -> stop_callback<Callback>;
92+
template <class _Callback>
93+
_LIBCPP_AVAILABILITY_SYNC stop_callback(stop_token, _Callback) -> stop_callback<_Callback>;
9494

9595
#endif // _LIBCPP_STD_VER >= 20
9696

libcxx/include/experimental/propagate_const

+4-4
Original file line numberDiff line numberDiff line change
@@ -284,8 +284,8 @@ public:
284284
return get();
285285
}
286286

287-
template <class _Tp_ = _Tp, class _Up = enable_if_t<is_convertible<
288-
const _Tp_, const element_type *>::value>>
287+
template <class _Dummy = _Tp, class _Up = enable_if_t<is_convertible<
288+
const _Dummy, const element_type *>::value>>
289289
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR operator const element_type *() const {
290290
return get();
291291
}
@@ -300,8 +300,8 @@ public:
300300
return get();
301301
}
302302

303-
template <class _Tp_ = _Tp, class _Up = enable_if_t<
304-
is_convertible<_Tp_, element_type *>::value>>
303+
template <class _Dummy = _Tp, class _Up = enable_if_t<
304+
is_convertible<_Dummy, element_type *>::value>>
305305
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR operator element_type *() {
306306
return get();
307307
}

libcxx/include/experimental/type_traits

+14-14
Original file line numberDiff line numberDiff line change
@@ -132,20 +132,20 @@ template <template<class...> class _Op, class... _Args>
132132
template <template<class...> class _Op, class... _Args>
133133
_LIBCPP_CONSTEXPR bool is_detected_v = is_detected<_Op, _Args...>::value;
134134

135-
template <class Default, template<class...> class _Op, class... _Args>
136-
using detected_or = _DETECTOR<Default, void, _Op, _Args...>;
137-
template <class Default, template<class...> class _Op, class... _Args>
138-
using detected_or_t = typename detected_or<Default, _Op, _Args...>::type;
139-
140-
template <class Expected, template<class...> class _Op, class... _Args>
141-
using is_detected_exact = is_same<Expected, detected_t<_Op, _Args...>>;
142-
template <class Expected, template<class...> class _Op, class... _Args>
143-
_LIBCPP_CONSTEXPR bool is_detected_exact_v = is_detected_exact<Expected, _Op, _Args...>::value;
144-
145-
template <class To, template<class...> class _Op, class... _Args>
146-
using is_detected_convertible = is_convertible<detected_t<_Op, _Args...>, To>;
147-
template <class To, template<class...> class _Op, class... _Args>
148-
_LIBCPP_CONSTEXPR bool is_detected_convertible_v = is_detected_convertible<To, _Op, _Args...>::value;
135+
template <class _Default, template<class...> class _Op, class... _Args>
136+
using detected_or = _DETECTOR<_Default, void, _Op, _Args...>;
137+
template <class _Default, template<class...> class _Op, class... _Args>
138+
using detected_or_t = typename detected_or<_Default, _Op, _Args...>::type;
139+
140+
template <class _Expected, template<class...> class _Op, class... _Args>
141+
using is_detected_exact = is_same<_Expected, detected_t<_Op, _Args...>>;
142+
template <class _Expected, template<class...> class _Op, class... _Args>
143+
_LIBCPP_CONSTEXPR bool is_detected_exact_v = is_detected_exact<_Expected, _Op, _Args...>::value;
144+
145+
template <class _To, template<class...> class _Op, class... _Args>
146+
using is_detected_convertible = is_convertible<detected_t<_Op, _Args...>, _To>;
147+
template <class _To, template<class...> class _Op, class... _Args>
148+
_LIBCPP_CONSTEXPR bool is_detected_convertible_v = is_detected_convertible<_To, _Op, _Args...>::value;
149149

150150

151151
_LIBCPP_END_NAMESPACE_LFTS

0 commit comments

Comments
 (0)