[libcxx-commits] [PATCH] D122092: [libc++] `bitset::operator[] const` should return bool

Nikolas Klauser via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Sat Mar 19 19:13:45 PDT 2022


philnik created this revision.
philnik added reviewers: Mordante, ldionne, var-const.
Herald added a subscriber: arphaman.
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++.

Fixes https://github.com/llvm/llvm-project/issues/10686


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D122092

Files:
  libcxx/include/bitset
  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
@@ -12,10 +12,12 @@
 #include <cassert>
 #include <cstddef>
 #include <vector>
+#include <type_traits>
 
 #include "../bitset_test_cases.h"
 #include "test_macros.h"
 
+
 template <std::size_t N>
 void test_index_const() {
     std::vector<std::bitset<N> > const cases = get_test_cases<N>();
@@ -25,6 +27,7 @@
             assert(v[N/2] == v.test(N/2));
         }
     }
+    static_assert(std::is_same<decltype(cases[0][0]), bool>::value, "");
 }
 
 int main(int, char**) {
Index: libcxx/include/bitset
===================================================================
--- libcxx/include/bitset
+++ libcxx/include/bitset
@@ -714,9 +714,8 @@
     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);}
+    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR bool operator[](size_t __p) const {return base::__make_ref(__p);}
+    _LIBCPP_INLINE_VISIBILITY              reference operator[](size_t __p)       {return base::__make_ref(__p);}
     _LIBCPP_INLINE_VISIBILITY
     unsigned long to_ulong() const;
     _LIBCPP_INLINE_VISIBILITY


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D122092.416754.patch
Type: text/x-patch
Size: 1615 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20220320/2cbc98b2/attachment.bin>


More information about the libcxx-commits mailing list