[libcxx-commits] [libcxx] 1ed5975 - [libc++] Add an ABI flag to make __bit_iterator trivially copyable (#172271)
via libcxx-commits
libcxx-commits at lists.llvm.org
Mon Dec 22 01:06:12 PST 2025
Author: Nikolas Klauser
Date: 2025-12-22T10:06:08+01:00
New Revision: 1ed5975b8deb9b6b15ba72089c6123c2ef52d393
URL: https://github.com/llvm/llvm-project/commit/1ed5975b8deb9b6b15ba72089c6123c2ef52d393
DIFF: https://github.com/llvm/llvm-project/commit/1ed5975b8deb9b6b15ba72089c6123c2ef52d393.diff
LOG: [libc++] Add an ABI flag to make __bit_iterator trivially copyable (#172271)
This makes it trivial for the purpose of calls as well, making an
unconditional ABI break most likely impossible.
Added:
libcxx/test/libcxx/containers/sequences/vector.bool/trivialty.compile.pass.cpp
Modified:
libcxx/docs/ABIGuarantees.rst
libcxx/include/__bit_reference
libcxx/include/__configuration/abi.h
Removed:
libcxx/test/libcxx/containers/sequences/vector.bool/trivial_for_purposes_of_call.pass.cpp
################################################################################
diff --git a/libcxx/docs/ABIGuarantees.rst b/libcxx/docs/ABIGuarantees.rst
index 4ca0451e1800c..37f38f4f392c6 100644
--- a/libcxx/docs/ABIGuarantees.rst
+++ b/libcxx/docs/ABIGuarantees.rst
@@ -162,6 +162,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..9f5108d745613 100644
--- a/libcxx/include/__bit_reference
+++ b/libcxx/include/__bit_reference
@@ -309,6 +309,15 @@ public:
{
}
+#ifdef _LIBCPP_ABI_TRIVIALLY_COPYABLE_BIT_ITERATOR
+ template <bool _IsConstDep = _IsConst, __enable_if_t<_IsConstDep, int> = 0>
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __bit_iterator(const __bit_iterator<_Cp, false>& __it) _NOEXCEPT
+ : __seg_(__it.__seg_),
+ __ctz_(__it.__ctz_) {}
+
+ _LIBCPP_HIDE_FROM_ABI __bit_iterator(const __bit_iterator&) = default;
+ _LIBCPP_HIDE_FROM_ABI __bit_iterator& operator=(const __bit_iterator&) = default;
+#else
// When _IsConst=false, this is the copy constructor.
// It is non-trivial. Making it trivial would break ABI.
// When _IsConst=true, this is a converting constructor;
@@ -329,6 +338,7 @@ public:
__ctz_ = __it.__ctz_;
return *this;
}
+#endif
_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 cced9c39749b7..a0782c52dcd90 100644
--- a/libcxx/include/__configuration/abi.h
+++ b/libcxx/include/__configuration/abi.h
@@ -85,6 +85,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))
diff --git a/libcxx/test/libcxx/containers/sequences/vector.bool/trivial_for_purposes_of_call.pass.cpp b/libcxx/test/libcxx/containers/sequences/vector.bool/trivialty.compile.pass.cpp
similarity index 72%
rename from libcxx/test/libcxx/containers/sequences/vector.bool/trivial_for_purposes_of_call.pass.cpp
rename to libcxx/test/libcxx/containers/sequences/vector.bool/trivialty.compile.pass.cpp
index 4d37b83ba9cd6..41831da00d31f 100644
--- a/libcxx/test/libcxx/containers/sequences/vector.bool/trivial_for_purposes_of_call.pass.cpp
+++ b/libcxx/test/libcxx/containers/sequences/vector.bool/trivialty.compile.pass.cpp
@@ -38,19 +38,13 @@ using IsTrivialForCall = std::integral_constant<
// Ignore the all-deleted case, it shouldn't occur here.
>;
-void test_const_iterator() {
- using It = std::vector<bool>::const_iterator;
- static_assert(IsTrivialForCall<It>::value, "");
-}
-
-void test_non_const_iterator() {
- using It = std::vector<bool>::iterator;
- static_assert(!IsTrivialForCall<It>::value, "");
-}
-
-int main(int, char**) {
- test_const_iterator();
- test_non_const_iterator();
-
- return 0;
-}
+static_assert(IsTrivialForCall<std::vector<bool>::const_iterator>::value, "");
+static_assert(std::is_trivially_copyable<std::vector<bool>::const_iterator>::value, "");
+
+#ifndef _LIBCPP_ABI_TRIVIALLY_COPYABLE_BIT_ITERATOR
+static_assert(!IsTrivialForCall<std::vector<bool>::iterator>::value, "");
+static_assert(!std::is_trivially_copyable<std::vector<bool>::iterator>::value, "");
+#else
+static_assert(IsTrivialForCall<std::vector<bool>::iterator>::value, "");
+static_assert(std::is_trivially_copyable<std::vector<bool>::iterator>::value, "");
+#endif
More information about the libcxx-commits
mailing list