[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 15 04:21:43 PDT 2022


philnik created this revision.
philnik added reviewers: Mordante, var-const.
Herald added a project: All.
philnik requested review of this revision.
Herald added a project: libc++.
Herald added a subscriber: libcxx-commits.
Herald added a reviewer: libc++.

`vector<bool>::const_reference` and `vector<bool>::const_iterator::reference` should be the same type.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D123851

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


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:


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D123851.423065.patch
Type: text/x-patch
Size: 1841 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20220415/d4f6486b/attachment-0001.bin>


More information about the libcxx-commits mailing list