Skip to content

Commit f86c2b6

Browse files
committed
[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
1 parent 50874a1 commit f86c2b6

File tree

9 files changed

+40
-39
lines changed

9 files changed

+40
-39
lines changed

libcxx/include/__bit_reference

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public:
8888
{return __bit_iterator<_Cp, false>(__seg_, static_cast<unsigned>(__libcpp_ctz(__mask_)));}
8989
private:
9090
_LIBCPP_INLINE_VISIBILITY
91-
__bit_reference(__storage_pointer __s, __storage_type __m) _NOEXCEPT
91+
explicit __bit_reference(__storage_pointer __s, __storage_type __m) _NOEXCEPT
9292
: __seg_(__s), __mask_(__m) {}
9393
};
9494

@@ -164,7 +164,7 @@ public:
164164
private:
165165
_LIBCPP_INLINE_VISIBILITY
166166
_LIBCPP_CONSTEXPR
167-
__bit_const_reference(__storage_pointer __s, __storage_type __m) _NOEXCEPT
167+
explicit __bit_const_reference(__storage_pointer __s, __storage_type __m) _NOEXCEPT
168168
: __seg_(__s), __mask_(__m) {}
169169

170170
__bit_const_reference& operator=(const __bit_const_reference&) = delete;
@@ -1250,7 +1250,7 @@ public:
12501250

12511251
private:
12521252
_LIBCPP_INLINE_VISIBILITY
1253-
__bit_iterator(__storage_pointer __s, unsigned __ctz) _NOEXCEPT
1253+
explicit __bit_iterator(__storage_pointer __s, unsigned __ctz) _NOEXCEPT
12541254
: __seg_(__s), __ctz_(__ctz) {}
12551255

12561256
friend typename _Cp::__self;

libcxx/include/__debug

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ struct _LIBCPP_TYPE_VIS __c_node
6666
__c_node& operator=(const __c_node&) = delete;
6767

6868
_LIBCPP_INLINE_VISIBILITY
69-
__c_node(void* __c, __c_node* __next)
69+
explicit __c_node(void* __c, __c_node* __next)
7070
: __c_(__c), __next_(__next), beg_(nullptr), end_(nullptr), cap_(nullptr) {}
7171
virtual ~__c_node();
7272

@@ -83,7 +83,7 @@ template <class _Cont>
8383
struct _C_node
8484
: public __c_node
8585
{
86-
_C_node(void* __c, __c_node* __n)
86+
explicit _C_node(void* __c, __c_node* __n)
8787
: __c_node(__c, __n) {}
8888

8989
virtual bool __dereferenceable(const void*) const;
@@ -141,7 +141,7 @@ class _LIBCPP_TYPE_VIS __libcpp_db
141141
__i_node** __iend_;
142142
size_t __isz_;
143143

144-
__libcpp_db();
144+
explicit __libcpp_db();
145145
public:
146146
__libcpp_db(const __libcpp_db&) = delete;
147147
__libcpp_db& operator=(const __libcpp_db&) = delete;

libcxx/include/__hash_table

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -362,14 +362,14 @@ public:
362362
private:
363363
#if _LIBCPP_DEBUG_LEVEL == 2
364364
_LIBCPP_INLINE_VISIBILITY
365-
__hash_iterator(__next_pointer __node, const void* __c) _NOEXCEPT
365+
explicit __hash_iterator(__next_pointer __node, const void* __c) _NOEXCEPT
366366
: __node_(__node)
367367
{
368368
__get_db()->__insert_ic(this, __c);
369369
}
370370
#else
371371
_LIBCPP_INLINE_VISIBILITY
372-
__hash_iterator(__next_pointer __node) _NOEXCEPT
372+
explicit __hash_iterator(__next_pointer __node) _NOEXCEPT
373373
: __node_(__node)
374374
{}
375375
#endif
@@ -480,14 +480,14 @@ public:
480480
private:
481481
#if _LIBCPP_DEBUG_LEVEL == 2
482482
_LIBCPP_INLINE_VISIBILITY
483-
__hash_const_iterator(__next_pointer __node, const void* __c) _NOEXCEPT
483+
explicit __hash_const_iterator(__next_pointer __node, const void* __c) _NOEXCEPT
484484
: __node_(__node)
485485
{
486486
__get_db()->__insert_ic(this, __c);
487487
}
488488
#else
489489
_LIBCPP_INLINE_VISIBILITY
490-
__hash_const_iterator(__next_pointer __node) _NOEXCEPT
490+
explicit __hash_const_iterator(__next_pointer __node) _NOEXCEPT
491491
: __node_(__node)
492492
{}
493493
#endif
@@ -593,8 +593,8 @@ public:
593593
private:
594594
#if _LIBCPP_DEBUG_LEVEL == 2
595595
_LIBCPP_INLINE_VISIBILITY
596-
__hash_local_iterator(__next_pointer __node, size_t __bucket,
597-
size_t __bucket_count, const void* __c) _NOEXCEPT
596+
explicit __hash_local_iterator(__next_pointer __node, size_t __bucket,
597+
size_t __bucket_count, const void* __c) _NOEXCEPT
598598
: __node_(__node),
599599
__bucket_(__bucket),
600600
__bucket_count_(__bucket_count)
@@ -605,8 +605,8 @@ private:
605605
}
606606
#else
607607
_LIBCPP_INLINE_VISIBILITY
608-
__hash_local_iterator(__next_pointer __node, size_t __bucket,
609-
size_t __bucket_count) _NOEXCEPT
608+
explicit __hash_local_iterator(__next_pointer __node, size_t __bucket,
609+
size_t __bucket_count) _NOEXCEPT
610610
: __node_(__node),
611611
__bucket_(__bucket),
612612
__bucket_count_(__bucket_count)
@@ -736,8 +736,8 @@ public:
736736
private:
737737
#if _LIBCPP_DEBUG_LEVEL == 2
738738
_LIBCPP_INLINE_VISIBILITY
739-
__hash_const_local_iterator(__next_pointer __node_ptr, size_t __bucket,
740-
size_t __bucket_count, const void* __c) _NOEXCEPT
739+
explicit __hash_const_local_iterator(__next_pointer __node_ptr, size_t __bucket,
740+
size_t __bucket_count, const void* __c) _NOEXCEPT
741741
: __node_(__node_ptr),
742742
__bucket_(__bucket),
743743
__bucket_count_(__bucket_count)
@@ -748,8 +748,8 @@ private:
748748
}
749749
#else
750750
_LIBCPP_INLINE_VISIBILITY
751-
__hash_const_local_iterator(__next_pointer __node_ptr, size_t __bucket,
752-
size_t __bucket_count) _NOEXCEPT
751+
explicit __hash_const_local_iterator(__next_pointer __node_ptr, size_t __bucket,
752+
size_t __bucket_count) _NOEXCEPT
753753
: __node_(__node_ptr),
754754
__bucket_(__bucket),
755755
__bucket_count_(__bucket_count)

libcxx/include/__iterator/common_iterator.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class common_iterator {
4242

4343
iter_value_t<_Iter> __value;
4444
// We can move __x because the only caller verifies that __x is not a reference.
45-
constexpr __proxy(iter_reference_t<_Iter>&& __x)
45+
constexpr explicit __proxy(iter_reference_t<_Iter>&& __x)
4646
: __value(_VSTD::move(__x)) {}
4747

4848
public:
@@ -55,7 +55,7 @@ class common_iterator {
5555
friend common_iterator;
5656

5757
iter_value_t<_Iter> __value;
58-
constexpr __postfix_proxy(iter_reference_t<_Iter>&& __x)
58+
constexpr explicit __postfix_proxy(iter_reference_t<_Iter>&& __x)
5959
: __value(_VSTD::forward<iter_reference_t<_Iter>>(__x)) {}
6060

6161
public:

libcxx/include/__iterator/istreambuf_iterator.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ _LIBCPP_SUPPRESS_DEPRECATED_POP
5050
{
5151
char_type __keep_;
5252
streambuf_type* __sbuf_;
53-
_LIBCPP_INLINE_VISIBILITY __proxy(char_type __c, streambuf_type* __s)
53+
_LIBCPP_INLINE_VISIBILITY
54+
explicit __proxy(char_type __c, streambuf_type* __s)
5455
: __keep_(__c), __sbuf_(__s) {}
5556
friend class istreambuf_iterator;
5657
public:

libcxx/include/__memory/compressed_pair.h

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,17 @@ struct __compressed_pair_elem {
3232
using reference = _Tp&;
3333
using const_reference = const _Tp&;
3434

35-
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR __compressed_pair_elem(__default_init_tag) {}
36-
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR __compressed_pair_elem(__value_init_tag) : __value_() {}
35+
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR explicit __compressed_pair_elem(__default_init_tag) {}
36+
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR explicit __compressed_pair_elem(__value_init_tag) : __value_() {}
3737

3838
template <class _Up, class = __enable_if_t<!is_same<__compressed_pair_elem, typename decay<_Up>::type>::value> >
39-
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR explicit
40-
__compressed_pair_elem(_Up&& __u) : __value_(std::forward<_Up>(__u)) {}
39+
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR
40+
explicit __compressed_pair_elem(_Up&& __u) : __value_(std::forward<_Up>(__u)) {}
4141

4242
#ifndef _LIBCPP_CXX03_LANG
4343
template <class... _Args, size_t... _Indices>
4444
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX14
45-
__compressed_pair_elem(piecewise_construct_t, tuple<_Args...> __args, __tuple_indices<_Indices...>)
45+
explicit __compressed_pair_elem(piecewise_construct_t, tuple<_Args...> __args, __tuple_indices<_Indices...>)
4646
: __value_(std::forward<_Args>(std::get<_Indices>(__args))...) {}
4747
#endif
4848

@@ -60,9 +60,9 @@ struct __compressed_pair_elem<_Tp, _Idx, true> : private _Tp {
6060
using const_reference = const _Tp&;
6161
using __value_type = _Tp;
6262

63-
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR __compressed_pair_elem() = default;
64-
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR __compressed_pair_elem(__default_init_tag) {}
65-
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR __compressed_pair_elem(__value_init_tag) : __value_type() {}
63+
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR explicit __compressed_pair_elem() = default;
64+
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR explicit __compressed_pair_elem(__default_init_tag) {}
65+
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR explicit __compressed_pair_elem(__value_init_tag) : __value_type() {}
6666

6767
template <class _Up, class = __enable_if_t<!is_same<__compressed_pair_elem, typename decay<_Up>::type>::value> >
6868
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR
@@ -101,17 +101,17 @@ class __compressed_pair : private __compressed_pair_elem<_T1, 0>,
101101
>
102102
>
103103
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR
104-
__compressed_pair() : _Base1(__value_init_tag()), _Base2(__value_init_tag()) {}
104+
explicit __compressed_pair() : _Base1(__value_init_tag()), _Base2(__value_init_tag()) {}
105105

106106
template <class _U1, class _U2>
107107
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR
108-
__compressed_pair(_U1&& __t1, _U2&& __t2) : _Base1(std::forward<_U1>(__t1)), _Base2(std::forward<_U2>(__t2)) {}
108+
explicit __compressed_pair(_U1&& __t1, _U2&& __t2) : _Base1(std::forward<_U1>(__t1)), _Base2(std::forward<_U2>(__t2)) {}
109109

110110
#ifndef _LIBCPP_CXX03_LANG
111111
template <class... _Args1, class... _Args2>
112112
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX14
113-
__compressed_pair(piecewise_construct_t __pc, tuple<_Args1...> __first_args,
114-
tuple<_Args2...> __second_args)
113+
explicit __compressed_pair(piecewise_construct_t __pc, tuple<_Args1...> __first_args,
114+
tuple<_Args2...> __second_args)
115115
: _Base1(__pc, std::move(__first_args), typename __make_tuple_indices<sizeof...(_Args1)>::type()),
116116
_Base2(__pc, std::move(__second_args), typename __make_tuple_indices<sizeof...(_Args2)>::type()) {}
117117
#endif

libcxx/include/__string

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1163,8 +1163,8 @@ struct __quoted_output_proxy
11631163
_CharT __delim;
11641164
_CharT __escape;
11651165

1166-
__quoted_output_proxy(_Iter __f, _Iter __l, _CharT __d, _CharT __e)
1167-
: __first(__f), __last(__l), __delim(__d), __escape(__e) {}
1166+
explicit __quoted_output_proxy(_Iter __f, _Iter __l, _CharT __d, _CharT __e)
1167+
: __first(__f), __last(__l), __delim(__d), __escape(__e) {}
11681168
// This would be a nice place for a string_ref
11691169
};
11701170

libcxx/include/deque

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ public:
450450
{return !(__x < __y);}
451451

452452
private:
453-
_LIBCPP_INLINE_VISIBILITY __deque_iterator(__map_iterator __m, pointer __p) _NOEXCEPT
453+
_LIBCPP_INLINE_VISIBILITY explicit __deque_iterator(__map_iterator __m, pointer __p) _NOEXCEPT
454454
: __m_iter_(__m), __ptr_(__p) {}
455455

456456
template <class _Tp, class _Ap> friend class __deque_base;

libcxx/include/iomanip

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,7 @@ basic_ostream<_CharT, _Traits>& operator<<(
573573
basic_ostream<_CharT, _Traits>& __os,
574574
const __quoted_output_proxy<_CharT, _Iter, _Traits> & __proxy)
575575
{
576-
return __quoted_output (__os, __proxy.__first, __proxy.__last, __proxy.__delim, __proxy.__escape);
576+
return __quoted_output(__os, __proxy.__first, __proxy.__last, __proxy.__delim, __proxy.__escape);
577577
}
578578

579579
template <class _CharT, class _Traits, class _Allocator>
@@ -583,8 +583,8 @@ struct __quoted_proxy
583583
_CharT __delim;
584584
_CharT __escape;
585585

586-
__quoted_proxy(basic_string<_CharT, _Traits, _Allocator> &__s, _CharT __d, _CharT __e)
587-
: __string(__s), __delim(__d), __escape(__e) {}
586+
explicit __quoted_proxy(basic_string<_CharT, _Traits, _Allocator> &__s, _CharT __d, _CharT __e)
587+
: __string(__s), __delim(__d), __escape(__e) {}
588588
};
589589

590590
template <class _CharT, class _Traits, class _Allocator>

0 commit comments

Comments
 (0)