[libcxx-commits] [PATCH] D123851: [libc++] Change vector<bool>::const_iterator::reference to bool in ABIv2

Nikolas Klauser via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Fri Apr 22 11:57:44 PDT 2022


This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
philnik marked an inline comment as done.
Closed by commit rG907ed12d950f: [libc++] Change vector<bool>::const_iterator::reference to bool in ABIv2 (authored by philnik).

Changed prior to commit:
  https://reviews.llvm.org/D123851?vs=424032&id=424557#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D123851/new/

https://reviews.llvm.org/D123851

Files:
  libcxx/docs/ReleaseNotes.rst
  libcxx/include/__bit_reference
  libcxx/test/std/containers/sequences/vector.bool/iterators.pass.cpp
  libcxx/test/std/containers/sequences/vector.bool/types.pass.cpp


Index: libcxx/test/std/containers/sequences/vector.bool/types.pass.cpp
===================================================================
--- libcxx/test/std/containers/sequences/vector.bool/types.pass.cpp
+++ libcxx/test/std/containers/sequences/vector.bool/types.pass.cpp
@@ -24,6 +24,7 @@
 //     typedef typename allocator_type::const_pointer   const_pointer;
 //     typedef std::reverse_iterator<iterator>          reverse_iterator;
 //     typedef std::reverse_iterator<const_iterator>    const_reverse_iterator;
+//     typedef bool                                     const_reference;
 // };
 
 #include <vector>
@@ -66,6 +67,9 @@
     static_assert((std::is_same<
         typename C::const_reverse_iterator,
         std::reverse_iterator<typename C::const_iterator> >::value), "");
+#if !defined(_LIBCPP_VERSION) || defined(_LIBCPP_ABI_BITSET_VECTOR_BOOL_CONST_SUBSCRIPT_RETURN_BOOL)
+    static_assert(std::is_same<typename C::const_reference, bool>::value, "");
+#endif
 }
 
 int main(int, char**)
Index: libcxx/test/std/containers/sequences/vector.bool/iterators.pass.cpp
===================================================================
--- libcxx/test/std/containers/sequences/vector.bool/iterators.pass.cpp
+++ libcxx/test/std/containers/sequences/vector.bool/iterators.pass.cpp
@@ -24,6 +24,15 @@
 
 int main(int, char**)
 {
+    using IterRefT = std::iterator_traits<std::vector<bool>::iterator>::reference;
+    ASSERT_SAME_TYPE(IterRefT, std::vector<bool>::reference);
+
+    using ConstIterRefT = std::iterator_traits<std::vector<bool>::const_iterator>::reference;
+#if !defined(_LIBCPP_VERSION) || defined(_LIBCPP_ABI_BITSET_VECTOR_BOOL_CONST_SUBSCRIPT_RETURN_BOOL)
+    ASSERT_SAME_TYPE(ConstIterRefT, bool);
+#else
+    ASSERT_SAME_TYPE(ConstIterRefT, std::__bit_const_reference<std::vector<bool> >);
+#endif
     {
         typedef bool T;
         typedef std::vector<T> C;
Index: libcxx/include/__bit_reference
===================================================================
--- libcxx/include/__bit_reference
+++ libcxx/include/__bit_reference
@@ -1109,7 +1109,11 @@
     typedef typename _Cp::difference_type                                                          difference_type;
     typedef bool                                                                                  value_type;
     typedef __bit_iterator                                                                        pointer;
+#ifndef _LIBCPP_ABI_BITSET_VECTOR_BOOL_CONST_SUBSCRIPT_RETURN_BOOL
     typedef typename conditional<_IsConst, __bit_const_reference<_Cp>, __bit_reference<_Cp> >::type reference;
+#else
+    using reference = typename conditional<_IsConst, bool, __bit_reference<_Cp>>::type;
+#endif
     typedef random_access_iterator_tag                                                            iterator_category;
 
 private:
@@ -1149,8 +1153,10 @@
         return *this;
     }
 
-    _LIBCPP_INLINE_VISIBILITY reference operator*() const _NOEXCEPT
-        {return reference(__seg_, __storage_type(1) << __ctz_);}
+    _LIBCPP_INLINE_VISIBILITY reference operator*() const _NOEXCEPT {
+        return typename conditional<_IsConst, __bit_const_reference<_Cp>, __bit_reference<_Cp> >
+                ::type(__seg_, __storage_type(1) << __ctz_);
+    }
 
     _LIBCPP_INLINE_VISIBILITY __bit_iterator& operator++()
     {
Index: libcxx/docs/ReleaseNotes.rst
===================================================================
--- libcxx/docs/ReleaseNotes.rst
+++ libcxx/docs/ReleaseNotes.rst
@@ -86,6 +86,9 @@
   supported anymore. Please migrate to using the new support for
   :ref:`assertions <assertions-mode>` instead.
 
+- ``vector<bool>::const_reference``, ``vector<bool>::const_iterator::reference``
+  and ``bitset::const_reference`` are now aliases for `bool` in the unstable ABI.
+
 ABI Changes
 -----------
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D123851.424557.patch
Type: text/x-patch
Size: 3850 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20220422/85b4dcac/attachment.bin>


More information about the libcxx-commits mailing list