[libcxx-commits] [libcxx] [libc++] Add an ABI flag to make __bit_iterator trivially copyable (PR #172271)
Nikolas Klauser via libcxx-commits
libcxx-commits at lists.llvm.org
Mon Dec 15 02:08:18 PST 2025
https://github.com/philnik777 created https://github.com/llvm/llvm-project/pull/172271
This makes it trivial for the purpose of calls as well, making an unconditional ABI break most likely impossible.
>From c4ff1b79423971a36557b71e340c80c55af8bd11 Mon Sep 17 00:00:00 2001
From: Nikolas Klauser <nikolasklauser at berlin.de>
Date: Mon, 15 Dec 2025 11:07:14 +0100
Subject: [PATCH] [libc++] Add an ABI flag to make __bit_iterator trivially
copyable
---
libcxx/docs/ABIGuarantees.rst | 4 ++++
libcxx/include/__bit_reference | 8 ++++++++
libcxx/include/__configuration/abi.h | 1 +
3 files changed, 13 insertions(+)
diff --git a/libcxx/docs/ABIGuarantees.rst b/libcxx/docs/ABIGuarantees.rst
index e680f5429880e..3b9b80991e50d 100644
--- a/libcxx/docs/ABIGuarantees.rst
+++ b/libcxx/docs/ABIGuarantees.rst
@@ -157,6 +157,10 @@ This flag adds ``[[clang::trivial_abi]]`` to ``unique_ptr``, which makes it triv
---------------------------------------------
This flag adds ``[[clang::trivial_abi]]`` to ``shared_ptr``, which makes it trivial for the purpose of calls.
+``_LIBCPP_ABI_TRIVIALLY_COPYABLE_BIT_ITERATOR``
+-----------------------------------------------
+This flag makes ``__bit_iterator`` (a.k.a. ``vector<bool>::iterator``) trivially copyable as well as trivial for the
+purpose of calls, since the copy constructor is made trivial.
Types that public aliases reference
===================================
diff --git a/libcxx/include/__bit_reference b/libcxx/include/__bit_reference
index 00bbc4100ddb9..4a96dd468fc58 100644
--- a/libcxx/include/__bit_reference
+++ b/libcxx/include/__bit_reference
@@ -314,10 +314,14 @@ public:
// When _IsConst=true, this is a converting constructor;
// the copy and move constructors are implicitly generated
// and trivial.
+#ifdef _LIBCPP_ABI_TRIVIALLY_COPYABLE_BIT_ITERATOR
+ template <bool _IsConstDep = _IsConst, __enable_if_t<_IsConstDep, int> = 0>
+#endif
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __bit_iterator(const __bit_iterator<_Cp, false>& __it) _NOEXCEPT
: __seg_(__it.__seg_),
__ctz_(__it.__ctz_) {}
+#ifndef _LIBCPP_ABI_TRIVIALLY_COPYABLE_BIT_ITERATOR
// When _IsConst=false, we have a user-provided copy constructor,
// so we must also provide a copy assignment operator because
// the implicit generation of a defaulted one is deprecated.
@@ -329,6 +333,10 @@ public:
__ctz_ = __it.__ctz_;
return *this;
}
+#else
+ __bit_iterator(const __bit_iterator&) = default;
+ __bit_iterator& operator=(const __bit_iterator&) = default;
+#endif // _LIBCPP_ABI_TRIVIALLY_COPYABLE_BIT_ITERATOR
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 reference operator*() const _NOEXCEPT {
_LIBCPP_ASSERT_INTERNAL(__ctz_ < __bits_per_word, "Dereferencing an invalid __bit_iterator.");
diff --git a/libcxx/include/__configuration/abi.h b/libcxx/include/__configuration/abi.h
index f30d0a5445b19..377710b55921b 100644
--- a/libcxx/include/__configuration/abi.h
+++ b/libcxx/include/__configuration/abi.h
@@ -84,6 +84,7 @@
# define _LIBCPP_ABI_USE_WRAP_ITER_IN_STD_ARRAY
# define _LIBCPP_ABI_USE_WRAP_ITER_IN_STD_STRING_VIEW
# define _LIBCPP_ABI_VARIANT_INDEX_TYPE_OPTIMIZATION
+# define _LIBCPP_ABI_TRIVIALLY_COPYABLE_BIT_ITERATOR
#elif _LIBCPP_ABI_VERSION == 1
# if !(defined(_LIBCPP_OBJECT_FORMAT_COFF) || defined(_LIBCPP_OBJECT_FORMAT_XCOFF))
More information about the libcxx-commits
mailing list