[libcxx-commits] [PATCH] D122092: [libc++] `bitset::operator[] const` should return bool
Nikolas Klauser via Phabricator via libcxx-commits
libcxx-commits at lists.llvm.org
Tue Mar 29 00:38:25 PDT 2022
philnik updated this revision to Diff 418810.
philnik added a comment.
- Try to fix CI
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D122092/new/
https://reviews.llvm.org/D122092
Files:
libcxx/include/__config
libcxx/include/bitset
libcxx/test/std/utilities/template.bitset/bitset.members/index.pass.cpp
libcxx/test/std/utilities/template.bitset/bitset.members/index_const.pass.cpp
Index: libcxx/test/std/utilities/template.bitset/bitset.members/index_const.pass.cpp
===================================================================
--- libcxx/test/std/utilities/template.bitset/bitset.members/index_const.pass.cpp
+++ libcxx/test/std/utilities/template.bitset/bitset.members/index_const.pass.cpp
@@ -25,6 +25,11 @@
assert(v[N/2] == v.test(N/2));
}
}
+#if !defined(_LIBCPP_VERSION) || defined(_LIBCPP_ABI_BITSET_CONST_SUBSCRIPT_RETURN_BOOL)
+ ASSERT_SAME_TYPE(decltype(cases[0][0]), bool);
+#else
+ ASSERT_SAME_TYPE(decltype(cases[0][0]), typename std::bitset<N>::const_reference);
+#endif
}
int main(int, char**) {
@@ -38,5 +43,16 @@
test_index_const<65>();
test_index_const<1000>();
+ std::bitset<1> set_;
+ set_[0] = false;
+ const auto& set = set_;
+ auto b = set[0];
+ set_[0] = true;
+#if !defined(_LIBCPP_VERSION) || defined(_LIBCPP_ABI_BITSET_CONST_SUBSCRIPT_RETURN_BOOL)
+ assert(!b);
+#else
+ assert(b);
+#endif // _LIBCPP_ABI_BITSET_CONST_SUBSCRIPT_RETURN_BOOL
+
return 0;
}
Index: libcxx/test/std/utilities/template.bitset/bitset.members/index.pass.cpp
===================================================================
--- libcxx/test/std/utilities/template.bitset/bitset.members/index.pass.cpp
+++ libcxx/test/std/utilities/template.bitset/bitset.members/index.pass.cpp
@@ -42,6 +42,7 @@
assert(r == false);
assert(v1.test(N/2) == false);
}
+ ASSERT_SAME_TYPE(decltype(v1[0]), typename std::bitset<N>::reference);
}
}
Index: libcxx/include/bitset
===================================================================
--- libcxx/include/bitset
+++ libcxx/include/bitset
@@ -714,9 +714,12 @@
bitset& flip(size_t __pos);
// element access:
- _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
- const_reference operator[](size_t __p) const {return base::__make_ref(__p);}
- _LIBCPP_INLINE_VISIBILITY reference operator[](size_t __p) {return base::__make_ref(__p);}
+#ifdef _LIBCPP_ABI_BITSET_CONST_SUBSCRIPT_RETURN_BOOL
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool operator[](size_t __p) const {return base::__make_ref(__p);}
+#else
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR const_reference operator[](size_t __p) const {return base::__make_ref(__p);}
+#endif
+ _LIBCPP_HIDE_FROM_ABI reference operator[](size_t __p) {return base::__make_ref(__p);}
_LIBCPP_INLINE_VISIBILITY
unsigned long to_ulong() const;
_LIBCPP_INLINE_VISIBILITY
Index: libcxx/include/__config
===================================================================
--- libcxx/include/__config
+++ libcxx/include/__config
@@ -114,6 +114,8 @@
# define _LIBCPP_ABI_DO_NOT_EXPORT_BASIC_STRING_COMMON
// Remove vector base class
# define _LIBCPP_ABI_DO_NOT_EXPORT_VECTOR_BASE_COMMON
+// According to the standard `bitset::operator[] const` returns bool
+# define _LIBCPP_ABI_BITSET_CONST_SUBSCRIPT_RETURN_BOOL
#elif _LIBCPP_ABI_VERSION == 1
# if !defined(_LIBCPP_OBJECT_FORMAT_COFF)
// Enable compiling copies of now inline methods into the dylib to support
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D122092.418810.patch
Type: text/x-patch
Size: 3191 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20220329/3e498c55/attachment-0001.bin>
More information about the libcxx-commits
mailing list