diff --git a/libcxx/.clang-tidy b/libcxx/.clang-tidy --- a/libcxx/.clang-tidy +++ b/libcxx/.clang-tidy @@ -1,2 +1,2 @@ InheritParentConfig: true -Checks: '-readability-identifier-naming' +Checks: '-readability-identifier-naming,-llvm-header-guard,-llvm-include-order' diff --git a/libcxx/include/__algorithm/copy.h b/libcxx/include/__algorithm/copy.h --- a/libcxx/include/__algorithm/copy.h +++ b/libcxx/include/__algorithm/copy.h @@ -62,14 +62,13 @@ _OutputIterator copy(_InputIterator __first, _InputIterator __last, _OutputIterator __result) { - if (__libcpp_is_constant_evaluated()) { + if (__libcpp_is_constant_evaluated()) return _VSTD::__copy_constexpr(__first, __last, __result); - } else { - return _VSTD::__rewrap_iter(__result, - _VSTD::__copy(_VSTD::__unwrap_iter(__first), - _VSTD::__unwrap_iter(__last), - _VSTD::__unwrap_iter(__result))); - } + + return _VSTD::__rewrap_iter(__result, + _VSTD::__copy(_VSTD::__unwrap_iter(__first), + _VSTD::__unwrap_iter(__last), + _VSTD::__unwrap_iter(__result))); } _LIBCPP_END_NAMESPACE_STD diff --git a/libcxx/include/__algorithm/copy_backward.h b/libcxx/include/__algorithm/copy_backward.h --- a/libcxx/include/__algorithm/copy_backward.h +++ b/libcxx/include/__algorithm/copy_backward.h @@ -64,14 +64,13 @@ copy_backward(_BidirectionalIterator1 __first, _BidirectionalIterator1 __last, _BidirectionalIterator2 __result) { - if (__libcpp_is_constant_evaluated()) { + if (__libcpp_is_constant_evaluated()) return _VSTD::__copy_backward_constexpr(__first, __last, __result); - } else { - return _VSTD::__rewrap_iter(__result, - _VSTD::__copy_backward(_VSTD::__unwrap_iter(__first), - _VSTD::__unwrap_iter(__last), - _VSTD::__unwrap_iter(__result))); - } + + return _VSTD::__rewrap_iter(__result, + _VSTD::__copy_backward(_VSTD::__unwrap_iter(__first), + _VSTD::__unwrap_iter(__last), + _VSTD::__unwrap_iter(__result))); } _LIBCPP_END_NAMESPACE_STD diff --git a/libcxx/include/__algorithm/is_permutation.h b/libcxx/include/__algorithm/is_permutation.h --- a/libcxx/include/__algorithm/is_permutation.h +++ b/libcxx/include/__algorithm/is_permutation.h @@ -86,7 +86,7 @@ break; if (__first1 == __last1) return __first2 == __last2; - else if (__first2 == __last2) + if (__first2 == __last2) return false; typedef typename iterator_traits<_ForwardIterator1>::difference_type _D1; diff --git a/libcxx/include/__algorithm/minmax_element.h b/libcxx/include/__algorithm/minmax_element.h --- a/libcxx/include/__algorithm/minmax_element.h +++ b/libcxx/include/__algorithm/minmax_element.h @@ -47,22 +47,19 @@ __result.second = __i; break; } + if (__comp(*__first, *__i)) + { + if (__comp(*__first, *__result.first)) + __result.first = __first; + if (!__comp(*__i, *__result.second)) + __result.second = __i; + } else { - if (__comp(*__first, *__i)) - { - if (__comp(*__first, *__result.first)) - __result.first = __first; - if (!__comp(*__i, *__result.second)) - __result.second = __i; - } - else - { - if (__comp(*__i, *__result.first)) - __result.first = __i; - if (!__comp(*__first, *__result.second)) - __result.second = __first; - } + if (__comp(*__i, *__result.first)) + __result.first = __i; + if (!__comp(*__first, *__result.second)) + __result.second = __first; } } } diff --git a/libcxx/include/__algorithm/move.h b/libcxx/include/__algorithm/move.h --- a/libcxx/include/__algorithm/move.h +++ b/libcxx/include/__algorithm/move.h @@ -63,14 +63,13 @@ _OutputIterator move(_InputIterator __first, _InputIterator __last, _OutputIterator __result) { - if (__libcpp_is_constant_evaluated()) { + if (__libcpp_is_constant_evaluated()) return _VSTD::__move_constexpr(__first, __last, __result); - } else { - return _VSTD::__rewrap_iter(__result, - _VSTD::__move(_VSTD::__unwrap_iter(__first), - _VSTD::__unwrap_iter(__last), - _VSTD::__unwrap_iter(__result))); - } + + return _VSTD::__rewrap_iter(__result, + _VSTD::__move(_VSTD::__unwrap_iter(__first), + _VSTD::__unwrap_iter(__last), + _VSTD::__unwrap_iter(__result))); } _LIBCPP_END_NAMESPACE_STD diff --git a/libcxx/include/__algorithm/move_backward.h b/libcxx/include/__algorithm/move_backward.h --- a/libcxx/include/__algorithm/move_backward.h +++ b/libcxx/include/__algorithm/move_backward.h @@ -64,14 +64,14 @@ move_backward(_BidirectionalIterator1 __first, _BidirectionalIterator1 __last, _BidirectionalIterator2 __result) { - if (__libcpp_is_constant_evaluated()) { + if (__libcpp_is_constant_evaluated()) return _VSTD::__move_backward_constexpr(__first, __last, __result); - } else { - return _VSTD::__rewrap_iter(__result, - _VSTD::__move_backward(_VSTD::__unwrap_iter(__first), - _VSTD::__unwrap_iter(__last), - _VSTD::__unwrap_iter(__result))); - } + + return _VSTD::__rewrap_iter(__result, + _VSTD::__move_backward(_VSTD::__unwrap_iter(__first), + _VSTD::__unwrap_iter(__last), + _VSTD::__unwrap_iter(__result))); + } _LIBCPP_END_NAMESPACE_STD diff --git a/libcxx/include/__algorithm/nth_element.h b/libcxx/include/__algorithm/nth_element.h --- a/libcxx/include/__algorithm/nth_element.h +++ b/libcxx/include/__algorithm/nth_element.h @@ -100,9 +100,9 @@ __j = __last; if (!__comp(*__first, *--__j)) { // we need a guard if *__first == *(__last-1) while (true) { - if (__i == __j) { + if (__i == __j) return; // [__first, __last) all equivalent elements - } else if (__comp(*__first, *__i)) { + if (__comp(*__first, *__i)) { swap(*__i, *__j); ++__n_swaps; ++__i; diff --git a/libcxx/include/__algorithm/sort.h b/libcxx/include/__algorithm/sort.h --- a/libcxx/include/__algorithm/sort.h +++ b/libcxx/include/__algorithm/sort.h @@ -442,13 +442,11 @@ __last = __i; continue; } - else + + if (__fs) { - if (__fs) - { - __first = ++__i; - continue; - } + __first = ++__i; + continue; } } // sort smaller range with recursive call and larger with tail recursion elimination diff --git a/libcxx/include/__bit_reference b/libcxx/include/__bit_reference --- a/libcxx/include/__bit_reference +++ b/libcxx/include/__bit_reference @@ -66,8 +66,10 @@ } _LIBCPP_INLINE_VISIBILITY - __bit_reference& operator=(const __bit_reference& __x) _NOEXCEPT - {return operator=(static_cast(__x));} + __bit_reference& operator=(const __bit_reference& __x) _NOEXCEPT { + operator=(static_cast(__x)); + return *this; + } _LIBCPP_INLINE_VISIBILITY void flip() _NOEXCEPT {*__seg_ ^= __mask_;} _LIBCPP_INLINE_VISIBILITY __bit_iterator<_Cp, false> operator&() const _NOEXCEPT @@ -921,13 +923,10 @@ _VSTD::copy(__b.begin(), __b.end(), _VSTD::copy(__middle, __last, __first)); break; } - else - { - __bit_iterator<_Cp, false> __mp = _VSTD::swap_ranges(__first, __middle, __middle); - __first = __middle; - __middle = __mp; - __d2 -= __d1; - } + __bit_iterator<_Cp, false> __mp = _VSTD::swap_ranges(__first, __middle, __middle); + __first = __middle; + __middle = __mp; + __d2 -= __d1; } else { @@ -938,13 +937,10 @@ _VSTD::copy_backward(__b.begin(), __b.end(), _VSTD::copy_backward(__first, __middle, __last)); break; } - else - { - __bit_iterator<_Cp, false> __mp = __first + __d2; - _VSTD::swap_ranges(__first, __mp, __middle); - __first = __mp; - __d1 -= __d2; - } + __bit_iterator<_Cp, false> __mp = __first + __d2; + _VSTD::swap_ranges(__first, __mp, __middle); + __first = __mp; + __d1 -= __d2; } } return __r; diff --git a/libcxx/include/__functional/bind.h b/libcxx/include/__functional/bind.h --- a/libcxx/include/__functional/bind.h +++ b/libcxx/include/__functional/bind.h @@ -70,7 +70,7 @@ /* inline */ constexpr __ph<10> _10{}; #endif // defined(_LIBCPP_CXX03_LANG) || defined(_LIBCPP_BUILDING_LIBRARY) -} // placeholders +} // namespace placeholders template struct __is_placeholder > diff --git a/libcxx/include/__functional/function.h b/libcxx/include/__functional/function.h --- a/libcxx/include/__functional/function.h +++ b/libcxx/include/__functional/function.h @@ -871,8 +871,7 @@ return nullptr; if (__policy_->__clone) // Out of line storage. return reinterpret_cast(__buf_.__large); - else - return reinterpret_cast(&__buf_.__small); + return reinterpret_cast(&__buf_.__small); } #endif // _LIBCPP_NO_RTTI }; @@ -946,7 +945,7 @@ #endif // _LIBCPP_HAS_EXTENSION_BLOCKS && !_LIBCPP_HAS_OBJC_ARC -} // __function +} // namespace __function template class _LIBCPP_TEMPLATE_VIS function<_Rp(_ArgTypes...)> diff --git a/libcxx/include/__functional/hash.h b/libcxx/include/__functional/hash.h --- a/libcxx/include/__functional/hash.h +++ b/libcxx/include/__functional/hash.h @@ -221,15 +221,13 @@ __murmur2_or_cityhash<_Size, 64>::operator()(const void* __key, _Size __len) { const char* __s = static_cast(__key); - if (__len <= 32) { - if (__len <= 16) { - return __hash_len_0_to_16(__s, __len); - } else { - return __hash_len_17_to_32(__s, __len); - } - } else if (__len <= 64) { + + if (__len <= 16) + return __hash_len_0_to_16(__s, __len); + if (__len <= 32) + return __hash_len_17_to_32(__s, __len); + if (__len <= 64) return __hash_len_33_to_64(__s, __len); - } // For strings over 64 bytes we hash the end first, and then as we // loop we keep 56 bytes of state: v, w, x, y, and z. diff --git a/libcxx/include/__memory/allocator.h b/libcxx/include/__memory/allocator.h --- a/libcxx/include/__memory/allocator.h +++ b/libcxx/include/__memory/allocator.h @@ -99,11 +99,9 @@ _Tp* allocate(size_t __n) { if (__n > allocator_traits::max_size(*this)) __throw_bad_array_new_length(); - if (__libcpp_is_constant_evaluated()) { + if (__libcpp_is_constant_evaluated()) return static_cast<_Tp*>(::operator new(__n * sizeof(_Tp))); - } else { - return static_cast<_Tp*>(_VSTD::__libcpp_allocate(__n * sizeof(_Tp), _LIBCPP_ALIGNOF(_Tp))); - } + return static_cast<_Tp*>(_VSTD::__libcpp_allocate(__n * sizeof(_Tp), _LIBCPP_ALIGNOF(_Tp))); } _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 @@ -181,11 +179,9 @@ const _Tp* allocate(size_t __n) { if (__n > allocator_traits::max_size(*this)) __throw_bad_array_new_length(); - if (__libcpp_is_constant_evaluated()) { + if (__libcpp_is_constant_evaluated()) return static_cast(::operator new(__n * sizeof(_Tp))); - } else { - return static_cast(_VSTD::__libcpp_allocate(__n * sizeof(_Tp), _LIBCPP_ALIGNOF(_Tp))); - } + return static_cast(_VSTD::__libcpp_allocate(__n * sizeof(_Tp), _LIBCPP_ALIGNOF(_Tp))); } _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 diff --git a/libcxx/include/__memory/auto_ptr.h b/libcxx/include/__memory/auto_ptr.h --- a/libcxx/include/__memory/auto_ptr.h +++ b/libcxx/include/__memory/auto_ptr.h @@ -37,6 +37,9 @@ _LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr& __p) _NOEXCEPT : __ptr_(__p.release()) {} template _LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr<_Up>& __p) _NOEXCEPT : __ptr_(__p.release()) {} + + // Reason: non-const auto_ptr& is required by the C++ standard + // NOLINTNEXTLINE(misc-unconventional-assign-operator) _LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr& __p) _NOEXCEPT {reset(__p.release()); return *this;} template _LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr<_Up>& __p) _NOEXCEPT diff --git a/libcxx/include/__memory/shared_ptr.h b/libcxx/include/__memory/shared_ptr.h --- a/libcxx/include/__memory/shared_ptr.h +++ b/libcxx/include/__memory/shared_ptr.h @@ -1206,6 +1206,8 @@ _LIBCPP_INLINE_VISIBILITY weak_ptr& operator=(weak_ptr const& __r) _NOEXCEPT; template + // Reason: clang-tidy does not recognize enable_if + // NOLINTNEXTLINE(misc-unconventional-assign-operator) typename enable_if < __compatible_with<_Yp, _Tp>::value, @@ -1217,6 +1219,8 @@ _LIBCPP_INLINE_VISIBILITY weak_ptr& operator=(weak_ptr&& __r) _NOEXCEPT; template + // Reason: clang-tidy does not recognize enable_if + // NOLINTNEXTLINE(misc-unconventional-assign-operator) typename enable_if < __compatible_with<_Yp, _Tp>::value, @@ -1226,6 +1230,8 @@ operator=(weak_ptr<_Yp>&& __r) _NOEXCEPT; template + // Reason: clang-tidy does not recognize enable_if + // NOLINTNEXTLINE(misc-unconventional-assign-operator) typename enable_if < __compatible_with<_Yp, _Tp>::value, @@ -1348,6 +1354,8 @@ return *this; } +// Reason: clang-tidy does not recognize enable_if +// NOLINTNEXTLINE(misc-unconventional-assign-operator) template template inline @@ -1371,6 +1379,8 @@ return *this; } +// Reason: clang-tidy does not recognize enable_if +// NOLINTNEXTLINE(misc-unconventional-assign-operator) template template inline @@ -1385,6 +1395,8 @@ return *this; } +// Reason: clang-tidy does not recognize enable_if +// NOLINTNEXTLINE(misc-unconventional-assign-operator) template template inline diff --git a/libcxx/include/__memory/unique_ptr.h b/libcxx/include/__memory/unique_ptr.h --- a/libcxx/include/__memory/unique_ptr.h +++ b/libcxx/include/__memory/unique_ptr.h @@ -249,6 +249,8 @@ #if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR) template + // Reason: clang-tidy does not recognize enable_if + // NOLINTNEXTLINE(misc-unconventional-assign-operator) _LIBCPP_INLINE_VISIBILITY typename enable_if::value && is_same<_Dp, default_delete<_Tp> >::value, diff --git a/libcxx/include/__nullptr b/libcxx/include/__nullptr --- a/libcxx/include/__nullptr +++ b/libcxx/include/__nullptr @@ -54,7 +54,7 @@ namespace std { typedef decltype(nullptr) nullptr_t; -} +} // namespace std #endif // _LIBCPP_HAS_NO_NULLPTR diff --git a/libcxx/include/__threading_support b/libcxx/include/__threading_support --- a/libcxx/include/__threading_support +++ b/libcxx/include/__threading_support @@ -296,7 +296,7 @@ return __ts; } -} +} // namespace __thread_detail #if defined(_LIBCPP_HAS_THREAD_API_PTHREAD) @@ -643,7 +643,7 @@ _LIBCPP_INLINE_VISIBILITY __thread_id get_id() _NOEXCEPT; -} // this_thread +} // namespace this_thread template<> struct hash<__thread_id>; @@ -713,7 +713,7 @@ return __libcpp_thread_get_current_id(); } -} // this_thread +} // namespace this_thread #endif // !_LIBCPP_HAS_NO_THREADS diff --git a/libcxx/include/__tree b/libcxx/include/__tree --- a/libcxx/include/__tree +++ b/libcxx/include/__tree @@ -1945,11 +1945,8 @@ __parent = static_cast<__parent_pointer>(__hint.__ptr_); return __parent->__left_; } - else - { - __parent = static_cast<__parent_pointer>(__prior.__ptr_); - return static_cast<__node_base_pointer>(__prior.__ptr_)->__right_; - } + __parent = static_cast<__parent_pointer>(__prior.__ptr_); + return static_cast<__node_base_pointer>(__prior.__ptr_)->__right_; } // __v < *prev(__hint) return __find_leaf_high(__parent, __v); @@ -2032,16 +2029,13 @@ __parent = static_cast<__parent_pointer>(__hint.__ptr_); return __parent->__left_; } - else - { - __parent = static_cast<__parent_pointer>(__prior.__ptr_); - return static_cast<__node_base_pointer>(__prior.__ptr_)->__right_; - } + __parent = static_cast<__parent_pointer>(__prior.__ptr_); + return static_cast<__node_base_pointer>(__prior.__ptr_)->__right_; } // __v <= *prev(__hint) return __find_equal(__parent, __v); } - else if (value_comp()(*__hint, __v)) // check after + if (value_comp()(*__hint, __v)) // check after { // *__hint < __v const_iterator __next = _VSTD::next(__hint); @@ -2053,11 +2047,8 @@ __parent = static_cast<__parent_pointer>(__hint.__ptr_); return static_cast<__node_base_pointer>(__hint.__ptr_)->__right_; } - else - { - __parent = static_cast<__parent_pointer>(__next.__ptr_); - return __parent->__left_; - } + __parent = static_cast<__parent_pointer>(__next.__ptr_); + return __parent->__left_; } // *next(__hint) <= __v return __find_equal(__parent, __v); diff --git a/libcxx/include/__utility/rel_ops.h b/libcxx/include/__utility/rel_ops.h --- a/libcxx/include/__utility/rel_ops.h +++ b/libcxx/include/__utility/rel_ops.h @@ -55,7 +55,7 @@ return !(__x < __y); } -} // rel_ops +} // namespace rel_ops _LIBCPP_END_NAMESPACE_STD diff --git a/libcxx/include/atomic b/libcxx/include/atomic --- a/libcxx/include/atomic +++ b/libcxx/include/atomic @@ -1768,9 +1768,14 @@ _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR atomic(_Tp __d) _NOEXCEPT : __base(__d) {} + // Reason: return type is required by C++ standard + // NOLINTNEXTLINE(misc-unconventional-assign-operator) _LIBCPP_INLINE_VISIBILITY _Tp operator=(_Tp __d) volatile _NOEXCEPT {__base::store(__d); return __d;} + + // Reason: return type is required by C++ standard + // NOLINTNEXTLINE(misc-unconventional-assign-operator) _LIBCPP_INLINE_VISIBILITY _Tp operator=(_Tp __d) _NOEXCEPT {__base::store(__d); return __d;} @@ -1795,9 +1800,14 @@ _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR atomic(_Tp* __d) _NOEXCEPT : __base(__d) {} + // Reason: return type is required by C++ standard + // NOLINTNEXTLINE(misc-unconventional-assign-operator) _LIBCPP_INLINE_VISIBILITY _Tp* operator=(_Tp* __d) volatile _NOEXCEPT {__base::store(__d); return __d;} + + // Reason: return type is required by C++ standard + // NOLINTNEXTLINE(misc-unconventional-assign-operator) _LIBCPP_INLINE_VISIBILITY _Tp* operator=(_Tp* __d) _NOEXCEPT {__base::store(__d); return __d;} diff --git a/libcxx/include/bit b/libcxx/include/bit --- a/libcxx/include/bit +++ b/libcxx/include/bit @@ -118,21 +118,19 @@ if (sizeof(_Tp) <= sizeof(unsigned int)) return __libcpp_ctz(static_cast(__t)); - else if (sizeof(_Tp) <= sizeof(unsigned long)) + if (sizeof(_Tp) <= sizeof(unsigned long)) return __libcpp_ctz(static_cast(__t)); - else if (sizeof(_Tp) <= sizeof(unsigned long long)) + if (sizeof(_Tp) <= sizeof(unsigned long long)) return __libcpp_ctz(static_cast(__t)); - else + + int __ret = 0; + const unsigned int __ulldigits = numeric_limits::digits; + while (static_cast(__t) == 0uLL) { - int __ret = 0; - const unsigned int __ulldigits = numeric_limits::digits; - while (static_cast(__t) == 0uLL) - { - __ret += __ulldigits; - __t >>= __ulldigits; - } - return __ret + __libcpp_ctz(static_cast(__t)); + __ret += __ulldigits; + __t >>= __ulldigits; } + return __ret + __libcpp_ctz(static_cast(__t)); } template @@ -146,25 +144,23 @@ if (sizeof(_Tp) <= sizeof(unsigned int)) return __libcpp_clz(static_cast(__t)) - (numeric_limits::digits - numeric_limits<_Tp>::digits); - else if (sizeof(_Tp) <= sizeof(unsigned long)) + if (sizeof(_Tp) <= sizeof(unsigned long)) return __libcpp_clz(static_cast(__t)) - (numeric_limits::digits - numeric_limits<_Tp>::digits); - else if (sizeof(_Tp) <= sizeof(unsigned long long)) + if (sizeof(_Tp) <= sizeof(unsigned long long)) return __libcpp_clz(static_cast(__t)) - (numeric_limits::digits - numeric_limits<_Tp>::digits); - else - { - int __ret = 0; - int __iter = 0; - const unsigned int __ulldigits = numeric_limits::digits; - while (true) { - __t = __rotr(__t, __ulldigits); - if ((__iter = __countl_zero(static_cast(__t))) != __ulldigits) - break; - __ret += __iter; - } - return __ret + __iter; - } + + int __ret = 0; + int __iter = 0; + const unsigned int __ulldigits = numeric_limits::digits; + while (true) { + __t = __rotr(__t, __ulldigits); + if ((__iter = __countl_zero(static_cast(__t))) != __ulldigits) + break; + __ret += __iter; + } + return __ret + __iter; } template @@ -194,20 +190,18 @@ static_assert(__libcpp_is_unsigned_integer<_Tp>::value, "__popcount requires an unsigned integer type"); if (sizeof(_Tp) <= sizeof(unsigned int)) return __libcpp_popcount(static_cast(__t)); - else if (sizeof(_Tp) <= sizeof(unsigned long)) + if (sizeof(_Tp) <= sizeof(unsigned long)) return __libcpp_popcount(static_cast(__t)); - else if (sizeof(_Tp) <= sizeof(unsigned long long)) + if (sizeof(_Tp) <= sizeof(unsigned long long)) return __libcpp_popcount(static_cast(__t)); - else + + int __ret = 0; + while (__t != 0) { - int __ret = 0; - while (__t != 0) - { - __ret += __libcpp_popcount(static_cast(__t)); - __t >>= numeric_limits::digits; - } - return __ret; + __ret += __libcpp_popcount(static_cast(__t)); + __t >>= numeric_limits::digits; } + return __ret; } // integral log base 2 diff --git a/libcxx/include/charconv b/libcxx/include/charconv --- a/libcxx/include/charconv +++ b/libcxx/include/charconv @@ -105,7 +105,7 @@ namespace __itoa { _LIBCPP_AVAILABILITY_TO_CHARS _LIBCPP_FUNC_VIS char* __u64toa(uint64_t __value, char* __buffer) _NOEXCEPT; _LIBCPP_AVAILABILITY_TO_CHARS _LIBCPP_FUNC_VIS char* __u32toa(uint32_t __value, char* __buffer) _NOEXCEPT; -} +} // namespace __itoa #ifndef _LIBCPP_CXX03_LANG @@ -298,8 +298,7 @@ if (__tx::digits <= __diff || __tx::__width(__value) <= __diff) return {__tx::__convert(__value, __first), errc(0)}; - else - return {__last, errc::value_too_large}; + return {__last, errc::value_too_large}; } template @@ -447,12 +446,11 @@ { if (__base <= 10) return {'0' <= __c && __c < '0' + __base, __c - '0'}; - else if (__in_pattern(__c)) + if (__in_pattern(__c)) return {true, __c - '0'}; - else if ('a' <= __c && __c < 'a' + __base - 10) + if ('a' <= __c && __c < 'a' + __base - 10) return {true, __c - 'a' + 10}; - else - return {'A' <= __c && __c < 'A' + __base - 10, __c - 'A' + 10}; + return {'A' <= __c && __c < 'A' + __base - 10, __c - 'A' + 10}; } template @@ -472,11 +470,8 @@ { if (__p == __first) return {__first, errc::invalid_argument}; - else - { - __value = 0; - return {__p, {}}; - } + __value = 0; + return {__p, {}}; } auto __r = __f(__p, __last, __value, __args...); diff --git a/libcxx/include/chrono b/libcxx/include/chrono --- a/libcxx/include/chrono +++ b/libcxx/include/chrono @@ -738,7 +738,7 @@ template struct __is_duration > : true_type {}; -} // chrono +} // namespace chrono template struct _LIBCPP_TEMPLATE_VIS common_type, @@ -1265,7 +1265,7 @@ _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR time_point max() _NOEXCEPT {return time_point(duration::max());} }; -} // chrono +} // namespace chrono template struct _LIBCPP_TEMPLATE_VIS common_type, @@ -2687,21 +2687,22 @@ constexpr hours make12(const hours& __h) noexcept { - if (__h == hours( 0)) return hours(12); - else if (__h <= hours(12)) return __h; - else return __h - hours(12); + if (__h == hours( 0)) + return hours(12); + if (__h <= hours(12)) + return __h; + return __h - hours(12); } constexpr hours make24(const hours& __h, bool __is_pm) noexcept { if (__is_pm) return __h == hours(12) ? __h : __h + hours(12); - else - return __h == hours(12) ? hours(0) : __h; + return __h == hours(12) ? hours(0) : __h; } #endif // _LIBCPP_STD_VER > 17 -} // chrono +} // namespace chrono #if _LIBCPP_STD_VER > 11 // Suffixes for duration literals [time.duration.literals] @@ -2786,11 +2787,12 @@ return chrono::year(static_cast(__y)); } #endif -}} +} // namespace chrono_literals +} // namespace literals namespace chrono { // hoist the literals into namespace std::chrono using namespace literals::chrono_literals; -} +} // namespace chrono #endif diff --git a/libcxx/include/cmath b/libcxx/include/cmath --- a/libcxx/include/cmath +++ b/libcxx/include/cmath @@ -623,8 +623,7 @@ const _Fp __x = __a + __t * (__b - __a); if ((__t > 1) == (__b > __a)) return __b < __x ? __x : __b; - else - return __x < __b ? __x : __b; + return __x < __b ? __x : __b; } constexpr float @@ -660,11 +659,10 @@ _IntT __clamp_to_integral(_RealT __r) _NOEXCEPT { using _Lim = numeric_limits<_IntT>; const _IntT _MaxVal = __max_representable_int_for_float<_IntT, _RealT>(); - if (__r >= ::nextafter(static_cast<_RealT>(_MaxVal), INFINITY)) { + if (__r >= ::nextafter(static_cast<_RealT>(_MaxVal), INFINITY)) return _Lim::max(); - } else if (__r <= _Lim::lowest()) { + if (__r <= _Lim::lowest()) return _Lim::min(); - } return static_cast<_IntT>(__r); } diff --git a/libcxx/include/complex b/libcxx/include/complex --- a/libcxx/include/complex +++ b/libcxx/include/complex @@ -1177,8 +1177,7 @@ { if (__x.real() > 0) return complex<_Tp>(__x.real(), copysign(__pi * _Tp(0.25), __x.imag())); - else - return complex<_Tp>(-__x.real(), copysign(__pi * _Tp(0.75), __x.imag())); + return complex<_Tp>(-__x.real(), copysign(__pi * _Tp(0.75), __x.imag())); } if (__x.real() < 0) return complex<_Tp>(-__x.real(), copysign(__pi, __x.imag())); @@ -1485,8 +1484,8 @@ { return { 0.0f, static_cast(__im) }; } - } -} + } // namespace complex_literals +} // namespace literals #endif _LIBCPP_END_NAMESPACE_STD diff --git a/libcxx/include/exception b/libcxx/include/exception --- a/libcxx/include/exception +++ b/libcxx/include/exception @@ -328,6 +328,6 @@ { } -} // std +} // namespace std #endif // _LIBCPP_EXCEPTION diff --git a/libcxx/include/ext/__hash b/libcxx/include/ext/__hash --- a/libcxx/include/ext/__hash +++ b/libcxx/include/ext/__hash @@ -129,6 +129,6 @@ return __c; } }; -} +} // namespace __gnu_cxx #endif // _LIBCPP_EXT_HASH diff --git a/libcxx/include/ext/hash_map b/libcxx/include/ext/hash_map --- a/libcxx/include/ext/hash_map +++ b/libcxx/include/ext/hash_map @@ -979,6 +979,6 @@ return !(__x == __y); } -} // __gnu_cxx +} // namespace __gnu_cxx #endif // _LIBCPP_HASH_MAP diff --git a/libcxx/include/ext/hash_set b/libcxx/include/ext/hash_set --- a/libcxx/include/ext/hash_set +++ b/libcxx/include/ext/hash_set @@ -654,6 +654,6 @@ return !(__x == __y); } -} // __gnu_cxx +} // namespace __gnu_cxx #endif // _LIBCPP_HASH_SET diff --git a/libcxx/include/filesystem b/libcxx/include/filesystem --- a/libcxx/include/filesystem +++ b/libcxx/include/filesystem @@ -1006,6 +1006,8 @@ } template + // Reason: clang-tidy does not recognize enable_if + // NOLINTNEXTLINE(misc-unconventional-assign-operator) _LIBCPP_INLINE_VISIBILITY _EnableIfPathable<_Source> operator=(const _Source& __src) { return this->assign(__src); diff --git a/libcxx/include/initializer_list b/libcxx/include/initializer_list --- a/libcxx/include/initializer_list +++ b/libcxx/include/initializer_list @@ -112,6 +112,6 @@ #endif // !defined(_LIBCPP_CXX03_LANG) -} // std +} // namespace std #endif // _LIBCPP_INITIALIZER_LIST diff --git a/libcxx/include/locale b/libcxx/include/locale --- a/libcxx/include/locale +++ b/libcxx/include/locale @@ -758,15 +758,14 @@ __err = ios_base::failbit; return 0; } - else if (__current_errno == ERANGE || - __ll < numeric_limits<_Tp>::min() || - numeric_limits<_Tp>::max() < __ll) + if (__current_errno == ERANGE || + __ll < numeric_limits<_Tp>::min() || + numeric_limits<_Tp>::max() < __ll) { __err = ios_base::failbit; if (__ll > 0) return numeric_limits<_Tp>::max(); - else - return numeric_limits<_Tp>::min(); + return numeric_limits<_Tp>::min(); } return static_cast<_Tp>(__ll); } @@ -798,7 +797,7 @@ __err = ios_base::failbit; return 0; } - else if (__current_errno == ERANGE || numeric_limits<_Tp>::max() < __ll) + if (__current_errno == ERANGE || numeric_limits<_Tp>::max() < __ll) { __err = ios_base::failbit; return numeric_limits<_Tp>::max(); @@ -852,7 +851,7 @@ __err = ios_base::failbit; return 0; } - else if (__current_errno == ERANGE) + if (__current_errno == ERANGE) __err = ios_base::failbit; return __ld; } @@ -1253,8 +1252,8 @@ ++__nf; break; } - else - *__oe++ = __ct.widen(*__nf); + + *__oe++ = __ct.widen(*__nf); } __ct.widen(__nf, __ne, __oe); __oe += __ne - __nf; diff --git a/libcxx/include/mutex b/libcxx/include/mutex --- a/libcxx/include/mutex +++ b/libcxx/include/mutex @@ -334,17 +334,12 @@ try_lock(_L0& __l0, _L1& __l1) { unique_lock<_L0> __u0(__l0, try_to_lock); - if (__u0.owns_lock()) - { - if (__l1.try_lock()) - { - __u0.release(); - return -1; - } - else - return 1; - } - return 0; + if (!__u0.owns_lock()) + return 0; + if (!__l1.try_lock()) + return 1; + __u0.release(); + return -1; } #ifndef _LIBCPP_CXX03_LANG diff --git a/libcxx/include/new b/libcxx/include/new --- a/libcxx/include/new +++ b/libcxx/include/new @@ -177,7 +177,7 @@ inline constexpr destroying_delete_t destroying_delete{}; #endif // _LIBCPP_STD_VER > 17 -} // std +} // namespace std #if defined(_LIBCPP_CXX03_LANG) #define _THROW_BAD_ALLOC throw(std::bad_alloc) @@ -291,9 +291,8 @@ if (__is_overaligned_for_new(__align)) { const align_val_t __align_val = static_cast(__align); return __do_deallocate_handle_size(__ptr, __size, __align_val); - } else { - return __do_deallocate_handle_size(__ptr, __size); } + return __do_deallocate_handle_size(__ptr, __size); #endif } @@ -305,9 +304,8 @@ if (__is_overaligned_for_new(__align)) { const align_val_t __align_val = static_cast(__align); return __libcpp_operator_delete(__ptr, __align_val); - } else { - return __libcpp_operator_delete(__ptr); } + return __libcpp_operator_delete(__ptr); #endif } diff --git a/libcxx/include/optional b/libcxx/include/optional --- a/libcxx/include/optional +++ b/libcxx/include/optional @@ -175,7 +175,7 @@ virtual const char* what() const _NOEXCEPT; }; -} // std +} // namespace std #if _LIBCPP_STD_VER > 14 diff --git a/libcxx/include/regex b/libcxx/include/regex --- a/libcxx/include/regex +++ b/libcxx/include/regex @@ -978,7 +978,7 @@ __re_err_parse }; -} // regex_constants +} // namespace regex_constants class _LIBCPP_EXCEPTION_ABI regex_error : public runtime_error @@ -2662,17 +2662,14 @@ // basic_regex& operator=(const basic_regex&) = default; // basic_regex& operator=(basic_regex&&) = default; _LIBCPP_INLINE_VISIBILITY - basic_regex& operator=(const value_type* __p) - {return assign(__p);} + basic_regex& operator=(const value_type* __p) { assign(__p); return *this; } #ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY - basic_regex& operator=(initializer_list __il) - {return assign(__il);} + basic_regex& operator=(initializer_list __il) { assign(__il); return *this; } #endif // _LIBCPP_CXX03_LANG template _LIBCPP_INLINE_VISIBILITY - basic_regex& operator=(const basic_string& __p) - {return assign(__p);} + basic_regex& operator=(const basic_string& __p) { assign(__p); return *this; } // assign: _LIBCPP_INLINE_VISIBILITY @@ -3880,9 +3877,9 @@ { if (*__temp == '=') return __parse_equivalence_class(++__temp, __last, __ml); - else if (*__temp == ':') + if (*__temp == ':') return __parse_character_class(++__temp, __last, __ml); - else if (*__temp == '.') + if (*__temp == '.') __first = __parse_collating_symbol(++__temp, __last, __start_range); } unsigned __grammar = __get_grammar(__flags_); @@ -6375,12 +6372,11 @@ __match_ = value_type(); return *this; } - else if (_VSTD::regex_search(__start, __end_, __match_, *__pregex_, - __flags_ | regex_constants::match_not_null | - regex_constants::match_continuous)) + if (_VSTD::regex_search(__start, __end_, __match_, *__pregex_, + __flags_ | regex_constants::match_not_null | + regex_constants::match_continuous)) return *this; - else - ++__start; + ++__start; } __flags_ |= regex_constants::match_prev_avail; if (!_VSTD::regex_search(__start, __end_, __match_, *__pregex_, __flags_)) diff --git a/libcxx/include/semaphore b/libcxx/include/semaphore --- a/libcxx/include/semaphore +++ b/libcxx/include/semaphore @@ -170,8 +170,7 @@ auto const current = Clock::now(); if (current >= __abs_time) return try_acquire(); - else - return try_acquire_for(__abs_time - current); + return try_acquire_for(__abs_time - current); } }; diff --git a/libcxx/include/sstream b/libcxx/include/sstream --- a/libcxx/include/sstream +++ b/libcxx/include/sstream @@ -444,7 +444,7 @@ __hm_ = this->pptr(); return string_type(this->pbase(), __hm_, __str_.get_allocator()); } - else if (__mode_ & ios_base::in) + if (__mode_ & ios_base::in) return string_type(this->eback(), this->egptr(), __str_.get_allocator()); return string_type(__str_.get_allocator()); } diff --git a/libcxx/include/stdexcept b/libcxx/include/stdexcept --- a/libcxx/include/stdexcept +++ b/libcxx/include/stdexcept @@ -209,7 +209,7 @@ #endif }; -} // std +} // namespace std _LIBCPP_BEGIN_NAMESPACE_STD diff --git a/libcxx/include/string b/libcxx/include/string --- a/libcxx/include/string +++ b/libcxx/include/string @@ -892,16 +892,16 @@ template ::value && !__is_same_uncvref<_Tp, basic_string>::value> > basic_string& operator=(const _Tp& __t) - {__self_view __sv = __t; return assign(__sv);} + {__self_view __sv = __t; assign(__sv); return *this; } #ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY basic_string& operator=(basic_string&& __str) _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value)); _LIBCPP_INLINE_VISIBILITY - basic_string& operator=(initializer_list __il) {return assign(__il.begin(), __il.size());} + basic_string& operator=(initializer_list __il) { assign(__il.begin(), __il.size()); return *this; } #endif - _LIBCPP_INLINE_VISIBILITY basic_string& operator=(const value_type* __s) {return assign(__s);} + _LIBCPP_INLINE_VISIBILITY basic_string& operator=(const value_type* __s) { assign(__s); return *this; } #if _LIBCPP_STD_VER > 20 basic_string& operator=(nullptr_t) = delete; #endif @@ -2420,10 +2420,12 @@ if (!__str.__is_long()) { __r_.first().__r = __str.__r_.first().__r; } else { - return __assign_no_alias(__str.data(), __str.size()); + __assign_no_alias(__str.data(), __str.size()); + return *this; } } else { - return __assign_no_alias(__str.data(), __str.size()); + __assign_no_alias(__str.data(), __str.size()); + return *this; } } return *this; @@ -4571,8 +4573,8 @@ { return basic_string (__str, __len); } - } -} + } // namespace string_literals +} // namespace literals #endif _LIBCPP_END_NAMESPACE_STD diff --git a/libcxx/include/string_view b/libcxx/include/string_view --- a/libcxx/include/string_view +++ b/libcxx/include/string_view @@ -912,8 +912,8 @@ { return basic_string_view (__str, __len); } - } -} + } // namespace string_view_literals +} // namespace literals #endif _LIBCPP_END_NAMESPACE_STD diff --git a/libcxx/include/system_error b/libcxx/include/system_error --- a/libcxx/include/system_error +++ b/libcxx/include/system_error @@ -268,6 +268,8 @@ } template + // Reason: clang-tidy does not recognize enable_if + // NOLINTNEXTLINE(misc-unconventional-assign-operator) _LIBCPP_INLINE_VISIBILITY typename enable_if < @@ -339,6 +341,8 @@ } template + // Reason: clang-tidy does not recognize enable_if + // NOLINTNEXTLINE(misc-unconventional-assign-operator) _LIBCPP_INLINE_VISIBILITY typename enable_if < diff --git a/libcxx/include/thread b/libcxx/include/thread --- a/libcxx/include/thread +++ b/libcxx/include/thread @@ -403,7 +403,7 @@ inline _LIBCPP_INLINE_VISIBILITY void yield() _NOEXCEPT {__libcpp_thread_yield();} -} // this_thread +} // namespace this_thread _LIBCPP_END_NAMESPACE_STD diff --git a/libcxx/include/tuple b/libcxx/include/tuple --- a/libcxx/include/tuple +++ b/libcxx/include/tuple @@ -1200,7 +1200,7 @@ static_assert(!is_same<_T1, _T1>::value, "type not in empty type list"); }; -} // namespace __find_detail; +} // namespace __find_detail template struct __find_exactly_one_t @@ -1251,13 +1251,15 @@ struct __ignore_t { template + // Reason: has to be const qualified to swallow variables if *this is const + // NOLINTNEXTLINE(misc-unconventional-assign-operator) _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const __ignore_t& operator=(_Tp&&) const {return *this;} }; namespace { constexpr __ignore_t ignore = __ignore_t(); -} +} // namespace template inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 diff --git a/libcxx/include/type_traits b/libcxx/include/type_traits --- a/libcxx/include/type_traits +++ b/libcxx/include/type_traits @@ -3953,7 +3953,7 @@ template struct __nothrow_swappable_with<_Tp, _Up, false> : false_type {}; -} // __detail +} // namespace __detail template struct __is_swappable diff --git a/libcxx/include/typeinfo b/libcxx/include/typeinfo --- a/libcxx/include/typeinfo +++ b/libcxx/include/typeinfo @@ -361,7 +361,7 @@ virtual const char* what() const _NOEXCEPT; }; -} // std +} // namespace std #endif // defined(_LIBCPP_ABI_VCRUNTIME) diff --git a/libcxx/include/valarray b/libcxx/include/valarray --- a/libcxx/include/valarray +++ b/libcxx/include/valarray @@ -1187,6 +1187,8 @@ public: template + // Reason: clang-tidy does not recognize enable_if + // NOLINTNEXTLINE(misc-unconventional-assign-operator) typename enable_if < __is_val_expr<_Expr>::value, @@ -1287,12 +1289,18 @@ slice_array(slice_array const&) = default; + // Reason: return type is required by C++ standard + // NOLINTNEXTLINE(misc-unconventional-assign-operator) _LIBCPP_INLINE_VISIBILITY const slice_array& operator=(const slice_array& __sa) const; + // Reason: return type is required by C++ standard + // NOLINTNEXTLINE(misc-unconventional-assign-operator) _LIBCPP_INLINE_VISIBILITY void operator=(const value_type& __x) const; + // Reason: return type is required by C++ standard + // NOLINTNEXTLINE(misc-unconventional-assign-operator) _LIBCPP_INLINE_VISIBILITY void operator=(const valarray& __va) const; @@ -1308,6 +1316,8 @@ template friend class sliceExpr; }; +// Reason: return type is required by C++ standard +// NOLINTNEXTLINE(misc-unconventional-assign-operator) template inline const slice_array<_Tp>& @@ -1320,6 +1330,8 @@ return *this; } +// Reason: return type is required by C++ standard +// NOLINTNEXTLINE(misc-unconventional-assign-operator) template template inline @@ -1335,6 +1347,8 @@ *__t = __v[__i]; } +// Reason: return type is required by C++ standard +// NOLINTNEXTLINE(misc-unconventional-assign-operator) template inline void slice_array<_Tp>::operator=(const valarray& __va) const @@ -1494,6 +1508,8 @@ *__t >>= __v[__i]; } +// Reason: return type is required by C++ standard +// NOLINTNEXTLINE(misc-unconventional-assign-operator) template inline void @@ -1579,6 +1595,8 @@ public: template + // Reason: return type is required by C++ standard + // NOLINTNEXTLINE(misc-unconventional-assign-operator) typename enable_if < __is_val_expr<_Expr>::value, @@ -1677,9 +1695,13 @@ _LIBCPP_INLINE_VISIBILITY operator>>=(const _Expr& __v) const; + // Reason: return type is required by C++ standard + // NOLINTNEXTLINE(misc-unconventional-assign-operator) _LIBCPP_INLINE_VISIBILITY const gslice_array& operator=(const gslice_array& __ga) const; + // Reason: return type is required by C++ standard + // NOLINTNEXTLINE(misc-unconventional-assign-operator) _LIBCPP_INLINE_VISIBILITY void operator=(const value_type& __x) const; @@ -1701,6 +1723,8 @@ template friend class valarray; }; +// Reason: return type is required by C++ standard +// NOLINTNEXTLINE(misc-unconventional-assign-operator) template template inline @@ -1877,6 +1901,8 @@ __vp_[*__i] >>= __v[__j]; } +// Reason: return type is required by C++ standard +// NOLINTNEXTLINE(misc-unconventional-assign-operator) template inline const gslice_array<_Tp>& @@ -1890,6 +1916,8 @@ return *this; } +// Reason: return type is required by C++ standard +// NOLINTNEXTLINE(misc-unconventional-assign-operator) template inline void @@ -1914,6 +1942,8 @@ public: template + // Reason: return type is required by C++ standard + // NOLINTNEXTLINE(misc-unconventional-assign-operator) typename enable_if < __is_val_expr<_Expr>::value, @@ -2014,9 +2044,13 @@ mask_array(const mask_array&) = default; + // Reason: return type is required by C++ standard + // NOLINTNEXTLINE(misc-unconventional-assign-operator) _LIBCPP_INLINE_VISIBILITY const mask_array& operator=(const mask_array& __ma) const; + // Reason: return type is required by C++ standard + // NOLINTNEXTLINE(misc-unconventional-assign-operator) _LIBCPP_INLINE_VISIBILITY void operator=(const value_type& __x) const; @@ -2035,6 +2069,8 @@ template friend class valarray; }; +// Reason: return type is required by C++ standard +// NOLINTNEXTLINE(misc-unconventional-assign-operator) template template inline @@ -2200,6 +2236,8 @@ __vp_[__1d_[__i]] >>= __v[__i]; } +// Reason: return type is required by C++ standard +// NOLINTNEXTLINE(misc-unconventional-assign-operator) template inline const mask_array<_Tp>& @@ -2211,6 +2249,8 @@ return *this; } +// Reason: return type is required by C++ standard +// NOLINTNEXTLINE(misc-unconventional-assign-operator) template inline void @@ -2270,6 +2310,8 @@ public: template + // Reason: return type is required by C++ standard + // NOLINTNEXTLINE(misc-unconventional-assign-operator) typename enable_if < __is_val_expr<_Expr>::value, @@ -2370,9 +2412,13 @@ indirect_array(const indirect_array&) = default; + // Reason: return type is required by C++ standard + // NOLINTNEXTLINE(misc-unconventional-assign-operator) _LIBCPP_INLINE_VISIBILITY const indirect_array& operator=(const indirect_array& __ia) const; + // Reason: return type is required by C++ standard + // NOLINTNEXTLINE(misc-unconventional-assign-operator) _LIBCPP_INLINE_VISIBILITY void operator=(const value_type& __x) const; @@ -2396,6 +2442,8 @@ template friend class valarray; }; +// Reason: return type is required by C++ standard +// NOLINTNEXTLINE(misc-unconventional-assign-operator) template template inline @@ -2561,6 +2609,8 @@ __vp_[__1d_[__i]] >>= __v[__i]; } +// Reason: return type is required by C++ standard +// NOLINTNEXTLINE(misc-unconventional-assign-operator) template inline const indirect_array<_Tp>& @@ -2574,6 +2624,8 @@ return *this; } +// Reason: return type is required by C++ standard +// NOLINTNEXTLINE(misc-unconventional-assign-operator) template inline void @@ -3056,7 +3108,7 @@ valarray<_Tp>::operator=(const valarray& __v) { if (this != _VSTD::addressof(__v)) - return __assign_range(__v.__begin_, __v.__end_); + __assign_range(__v.__begin_, __v.__end_); return *this; } @@ -3080,7 +3132,8 @@ valarray<_Tp>& valarray<_Tp>::operator=(initializer_list __il) { - return __assign_range(__il.begin(), __il.end()); + __assign_range(__il.begin(), __il.end()); + return *this; } #endif // _LIBCPP_CXX03_LANG