From f86c2b6f1f3682cef24fb74edd5d02eb8f2707f7 Mon Sep 17 00:00:00 2001 From: Arthur O'Dwyer Date: Wed, 9 Feb 2022 17:30:46 -0500 Subject: [PATCH] [libc++] Add `explicit` to a bunch of internal detail ctors. Notably the following ctors remain non-explicit because they are used as implicit conversions in too many places: * __debug_less(_Compare&) * __map_iterator(_TreeIterator) * __map_const_iterator(_TreeIterator) * __hash_map_iterator(_HashIterator) * __hash_map_const_iterator(_HashIterator) Differential Revision: https://reviews.llvm.org/D119894 --- libcxx/include/__bit_reference | 6 +++--- libcxx/include/__debug | 6 +++--- libcxx/include/__hash_table | 24 ++++++++++++------------ libcxx/include/__iterator/common_iterator.h | 4 ++-- libcxx/include/__iterator/istreambuf_iterator.h | 3 ++- libcxx/include/__memory/compressed_pair.h | 24 ++++++++++++------------ libcxx/include/__string | 4 ++-- libcxx/include/deque | 2 +- libcxx/include/iomanip | 6 +++--- 9 files changed, 40 insertions(+), 39 deletions(-) diff --git a/libcxx/include/__bit_reference b/libcxx/include/__bit_reference index 423acee..53af4b3 100644 --- a/libcxx/include/__bit_reference +++ b/libcxx/include/__bit_reference @@ -88,7 +88,7 @@ public: {return __bit_iterator<_Cp, false>(__seg_, static_cast(__libcpp_ctz(__mask_)));} private: _LIBCPP_INLINE_VISIBILITY - __bit_reference(__storage_pointer __s, __storage_type __m) _NOEXCEPT + explicit __bit_reference(__storage_pointer __s, __storage_type __m) _NOEXCEPT : __seg_(__s), __mask_(__m) {} }; @@ -164,7 +164,7 @@ public: private: _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR - __bit_const_reference(__storage_pointer __s, __storage_type __m) _NOEXCEPT + explicit __bit_const_reference(__storage_pointer __s, __storage_type __m) _NOEXCEPT : __seg_(__s), __mask_(__m) {} __bit_const_reference& operator=(const __bit_const_reference&) = delete; @@ -1250,7 +1250,7 @@ public: private: _LIBCPP_INLINE_VISIBILITY - __bit_iterator(__storage_pointer __s, unsigned __ctz) _NOEXCEPT + explicit __bit_iterator(__storage_pointer __s, unsigned __ctz) _NOEXCEPT : __seg_(__s), __ctz_(__ctz) {} friend typename _Cp::__self; diff --git a/libcxx/include/__debug b/libcxx/include/__debug index b7677a2..a4160b3 100644 --- a/libcxx/include/__debug +++ b/libcxx/include/__debug @@ -66,7 +66,7 @@ struct _LIBCPP_TYPE_VIS __c_node __c_node& operator=(const __c_node&) = delete; _LIBCPP_INLINE_VISIBILITY - __c_node(void* __c, __c_node* __next) + explicit __c_node(void* __c, __c_node* __next) : __c_(__c), __next_(__next), beg_(nullptr), end_(nullptr), cap_(nullptr) {} virtual ~__c_node(); @@ -83,7 +83,7 @@ template struct _C_node : public __c_node { - _C_node(void* __c, __c_node* __n) + explicit _C_node(void* __c, __c_node* __n) : __c_node(__c, __n) {} virtual bool __dereferenceable(const void*) const; @@ -141,7 +141,7 @@ class _LIBCPP_TYPE_VIS __libcpp_db __i_node** __iend_; size_t __isz_; - __libcpp_db(); + explicit __libcpp_db(); public: __libcpp_db(const __libcpp_db&) = delete; __libcpp_db& operator=(const __libcpp_db&) = delete; diff --git a/libcxx/include/__hash_table b/libcxx/include/__hash_table index 36f2ef7..5de00a3 100644 --- a/libcxx/include/__hash_table +++ b/libcxx/include/__hash_table @@ -362,14 +362,14 @@ public: private: #if _LIBCPP_DEBUG_LEVEL == 2 _LIBCPP_INLINE_VISIBILITY - __hash_iterator(__next_pointer __node, const void* __c) _NOEXCEPT + explicit __hash_iterator(__next_pointer __node, const void* __c) _NOEXCEPT : __node_(__node) { __get_db()->__insert_ic(this, __c); } #else _LIBCPP_INLINE_VISIBILITY - __hash_iterator(__next_pointer __node) _NOEXCEPT + explicit __hash_iterator(__next_pointer __node) _NOEXCEPT : __node_(__node) {} #endif @@ -480,14 +480,14 @@ public: private: #if _LIBCPP_DEBUG_LEVEL == 2 _LIBCPP_INLINE_VISIBILITY - __hash_const_iterator(__next_pointer __node, const void* __c) _NOEXCEPT + explicit __hash_const_iterator(__next_pointer __node, const void* __c) _NOEXCEPT : __node_(__node) { __get_db()->__insert_ic(this, __c); } #else _LIBCPP_INLINE_VISIBILITY - __hash_const_iterator(__next_pointer __node) _NOEXCEPT + explicit __hash_const_iterator(__next_pointer __node) _NOEXCEPT : __node_(__node) {} #endif @@ -593,8 +593,8 @@ public: private: #if _LIBCPP_DEBUG_LEVEL == 2 _LIBCPP_INLINE_VISIBILITY - __hash_local_iterator(__next_pointer __node, size_t __bucket, - size_t __bucket_count, const void* __c) _NOEXCEPT + explicit __hash_local_iterator(__next_pointer __node, size_t __bucket, + size_t __bucket_count, const void* __c) _NOEXCEPT : __node_(__node), __bucket_(__bucket), __bucket_count_(__bucket_count) @@ -605,8 +605,8 @@ private: } #else _LIBCPP_INLINE_VISIBILITY - __hash_local_iterator(__next_pointer __node, size_t __bucket, - size_t __bucket_count) _NOEXCEPT + explicit __hash_local_iterator(__next_pointer __node, size_t __bucket, + size_t __bucket_count) _NOEXCEPT : __node_(__node), __bucket_(__bucket), __bucket_count_(__bucket_count) @@ -736,8 +736,8 @@ public: private: #if _LIBCPP_DEBUG_LEVEL == 2 _LIBCPP_INLINE_VISIBILITY - __hash_const_local_iterator(__next_pointer __node_ptr, size_t __bucket, - size_t __bucket_count, const void* __c) _NOEXCEPT + explicit __hash_const_local_iterator(__next_pointer __node_ptr, size_t __bucket, + size_t __bucket_count, const void* __c) _NOEXCEPT : __node_(__node_ptr), __bucket_(__bucket), __bucket_count_(__bucket_count) @@ -748,8 +748,8 @@ private: } #else _LIBCPP_INLINE_VISIBILITY - __hash_const_local_iterator(__next_pointer __node_ptr, size_t __bucket, - size_t __bucket_count) _NOEXCEPT + explicit __hash_const_local_iterator(__next_pointer __node_ptr, size_t __bucket, + size_t __bucket_count) _NOEXCEPT : __node_(__node_ptr), __bucket_(__bucket), __bucket_count_(__bucket_count) diff --git a/libcxx/include/__iterator/common_iterator.h b/libcxx/include/__iterator/common_iterator.h index 505e4f1..abbd8f4 100644 --- a/libcxx/include/__iterator/common_iterator.h +++ b/libcxx/include/__iterator/common_iterator.h @@ -42,7 +42,7 @@ class common_iterator { iter_value_t<_Iter> __value; // We can move __x because the only caller verifies that __x is not a reference. - constexpr __proxy(iter_reference_t<_Iter>&& __x) + constexpr explicit __proxy(iter_reference_t<_Iter>&& __x) : __value(_VSTD::move(__x)) {} public: @@ -55,7 +55,7 @@ class common_iterator { friend common_iterator; iter_value_t<_Iter> __value; - constexpr __postfix_proxy(iter_reference_t<_Iter>&& __x) + constexpr explicit __postfix_proxy(iter_reference_t<_Iter>&& __x) : __value(_VSTD::forward>(__x)) {} public: diff --git a/libcxx/include/__iterator/istreambuf_iterator.h b/libcxx/include/__iterator/istreambuf_iterator.h index 3b16f79..bc53a6a 100644 --- a/libcxx/include/__iterator/istreambuf_iterator.h +++ b/libcxx/include/__iterator/istreambuf_iterator.h @@ -50,7 +50,8 @@ private: { char_type __keep_; streambuf_type* __sbuf_; - _LIBCPP_INLINE_VISIBILITY __proxy(char_type __c, streambuf_type* __s) + _LIBCPP_INLINE_VISIBILITY + explicit __proxy(char_type __c, streambuf_type* __s) : __keep_(__c), __sbuf_(__s) {} friend class istreambuf_iterator; public: diff --git a/libcxx/include/__memory/compressed_pair.h b/libcxx/include/__memory/compressed_pair.h index 852031f..89e5820 100644 --- a/libcxx/include/__memory/compressed_pair.h +++ b/libcxx/include/__memory/compressed_pair.h @@ -32,17 +32,17 @@ struct __compressed_pair_elem { using reference = _Tp&; using const_reference = const _Tp&; - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR __compressed_pair_elem(__default_init_tag) {} - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR __compressed_pair_elem(__value_init_tag) : __value_() {} + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR explicit __compressed_pair_elem(__default_init_tag) {} + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR explicit __compressed_pair_elem(__value_init_tag) : __value_() {} template ::type>::value> > - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR explicit - __compressed_pair_elem(_Up&& __u) : __value_(std::forward<_Up>(__u)) {} + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR + explicit __compressed_pair_elem(_Up&& __u) : __value_(std::forward<_Up>(__u)) {} #ifndef _LIBCPP_CXX03_LANG template _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX14 - __compressed_pair_elem(piecewise_construct_t, tuple<_Args...> __args, __tuple_indices<_Indices...>) + explicit __compressed_pair_elem(piecewise_construct_t, tuple<_Args...> __args, __tuple_indices<_Indices...>) : __value_(std::forward<_Args>(std::get<_Indices>(__args))...) {} #endif @@ -60,9 +60,9 @@ struct __compressed_pair_elem<_Tp, _Idx, true> : private _Tp { using const_reference = const _Tp&; using __value_type = _Tp; - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR __compressed_pair_elem() = default; - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR __compressed_pair_elem(__default_init_tag) {} - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR __compressed_pair_elem(__value_init_tag) : __value_type() {} + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR explicit __compressed_pair_elem() = default; + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR explicit __compressed_pair_elem(__default_init_tag) {} + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR explicit __compressed_pair_elem(__value_init_tag) : __value_type() {} template ::type>::value> > _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR @@ -101,17 +101,17 @@ public: > > _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR - __compressed_pair() : _Base1(__value_init_tag()), _Base2(__value_init_tag()) {} + explicit __compressed_pair() : _Base1(__value_init_tag()), _Base2(__value_init_tag()) {} template _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR - __compressed_pair(_U1&& __t1, _U2&& __t2) : _Base1(std::forward<_U1>(__t1)), _Base2(std::forward<_U2>(__t2)) {} + explicit __compressed_pair(_U1&& __t1, _U2&& __t2) : _Base1(std::forward<_U1>(__t1)), _Base2(std::forward<_U2>(__t2)) {} #ifndef _LIBCPP_CXX03_LANG template _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX14 - __compressed_pair(piecewise_construct_t __pc, tuple<_Args1...> __first_args, - tuple<_Args2...> __second_args) + explicit __compressed_pair(piecewise_construct_t __pc, tuple<_Args1...> __first_args, + tuple<_Args2...> __second_args) : _Base1(__pc, std::move(__first_args), typename __make_tuple_indices::type()), _Base2(__pc, std::move(__second_args), typename __make_tuple_indices::type()) {} #endif diff --git a/libcxx/include/__string b/libcxx/include/__string index 479893b..bde5e5c 100644 --- a/libcxx/include/__string +++ b/libcxx/include/__string @@ -1163,8 +1163,8 @@ struct __quoted_output_proxy _CharT __delim; _CharT __escape; - __quoted_output_proxy(_Iter __f, _Iter __l, _CharT __d, _CharT __e) - : __first(__f), __last(__l), __delim(__d), __escape(__e) {} + explicit __quoted_output_proxy(_Iter __f, _Iter __l, _CharT __d, _CharT __e) + : __first(__f), __last(__l), __delim(__d), __escape(__e) {} // This would be a nice place for a string_ref }; diff --git a/libcxx/include/deque b/libcxx/include/deque index b0fd148..a6f2a67 100644 --- a/libcxx/include/deque +++ b/libcxx/include/deque @@ -450,7 +450,7 @@ public: {return !(__x < __y);} private: - _LIBCPP_INLINE_VISIBILITY __deque_iterator(__map_iterator __m, pointer __p) _NOEXCEPT + _LIBCPP_INLINE_VISIBILITY explicit __deque_iterator(__map_iterator __m, pointer __p) _NOEXCEPT : __m_iter_(__m), __ptr_(__p) {} template friend class __deque_base; diff --git a/libcxx/include/iomanip b/libcxx/include/iomanip index 3d791541..05826cd 100644 --- a/libcxx/include/iomanip +++ b/libcxx/include/iomanip @@ -573,7 +573,7 @@ basic_ostream<_CharT, _Traits>& operator<<( basic_ostream<_CharT, _Traits>& __os, const __quoted_output_proxy<_CharT, _Iter, _Traits> & __proxy) { - return __quoted_output (__os, __proxy.__first, __proxy.__last, __proxy.__delim, __proxy.__escape); + return __quoted_output(__os, __proxy.__first, __proxy.__last, __proxy.__delim, __proxy.__escape); } template @@ -583,8 +583,8 @@ struct __quoted_proxy _CharT __delim; _CharT __escape; - __quoted_proxy(basic_string<_CharT, _Traits, _Allocator> &__s, _CharT __d, _CharT __e) - : __string(__s), __delim(__d), __escape(__e) {} + explicit __quoted_proxy(basic_string<_CharT, _Traits, _Allocator> &__s, _CharT __d, _CharT __e) + : __string(__s), __delim(__d), __escape(__e) {} }; template -- 2.7.4