Skip to content

Commit c4ff1b7

Browse files
committed
[libc++] Add an ABI flag to make __bit_iterator trivially copyable
1 parent b97d247 commit c4ff1b7

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

libcxx/docs/ABIGuarantees.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,10 @@ This flag adds ``[[clang::trivial_abi]]`` to ``unique_ptr``, which makes it triv
157157
---------------------------------------------
158158
This flag adds ``[[clang::trivial_abi]]`` to ``shared_ptr``, which makes it trivial for the purpose of calls.
159159

160+
``_LIBCPP_ABI_TRIVIALLY_COPYABLE_BIT_ITERATOR``
161+
-----------------------------------------------
162+
This flag makes ``__bit_iterator`` (a.k.a. ``vector<bool>::iterator``) trivially copyable as well as trivial for the
163+
purpose of calls, since the copy constructor is made trivial.
160164

161165
Types that public aliases reference
162166
===================================

libcxx/include/__bit_reference

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,10 +314,14 @@ public:
314314
// When _IsConst=true, this is a converting constructor;
315315
// the copy and move constructors are implicitly generated
316316
// and trivial.
317+
#ifdef _LIBCPP_ABI_TRIVIALLY_COPYABLE_BIT_ITERATOR
318+
template <bool _IsConstDep = _IsConst, __enable_if_t<_IsConstDep, int> = 0>
319+
#endif
317320
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __bit_iterator(const __bit_iterator<_Cp, false>& __it) _NOEXCEPT
318321
: __seg_(__it.__seg_),
319322
__ctz_(__it.__ctz_) {}
320323

324+
#ifndef _LIBCPP_ABI_TRIVIALLY_COPYABLE_BIT_ITERATOR
321325
// When _IsConst=false, we have a user-provided copy constructor,
322326
// so we must also provide a copy assignment operator because
323327
// the implicit generation of a defaulted one is deprecated.
@@ -329,6 +333,10 @@ public:
329333
__ctz_ = __it.__ctz_;
330334
return *this;
331335
}
336+
#else
337+
__bit_iterator(const __bit_iterator&) = default;
338+
__bit_iterator& operator=(const __bit_iterator&) = default;
339+
#endif // _LIBCPP_ABI_TRIVIALLY_COPYABLE_BIT_ITERATOR
332340

333341
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 reference operator*() const _NOEXCEPT {
334342
_LIBCPP_ASSERT_INTERNAL(__ctz_ < __bits_per_word, "Dereferencing an invalid __bit_iterator.");

libcxx/include/__configuration/abi.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@
8484
# define _LIBCPP_ABI_USE_WRAP_ITER_IN_STD_ARRAY
8585
# define _LIBCPP_ABI_USE_WRAP_ITER_IN_STD_STRING_VIEW
8686
# define _LIBCPP_ABI_VARIANT_INDEX_TYPE_OPTIMIZATION
87+
# define _LIBCPP_ABI_TRIVIALLY_COPYABLE_BIT_ITERATOR
8788

8889
#elif _LIBCPP_ABI_VERSION == 1
8990
# if !(defined(_LIBCPP_OBJECT_FORMAT_COFF) || defined(_LIBCPP_OBJECT_FORMAT_XCOFF))

0 commit comments

Comments
 (0)