[libcxx-commits] [PATCH] D144279: [libc++][format] Fixes formatting vector<bool>

Mark de Wever via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Sat Mar 4 05:00:08 PST 2023


This revision was automatically updated to reflect the committed changes.
Mordante marked an inline comment as done.
Closed by commit rG7e4639d28f44: [libc++][format] Fixes formatting vector<bool> (authored by Mordante).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144279

Files:
  libcxx/include/__bit_reference
  libcxx/test/std/containers/container.adaptors/container.adaptors.format/format.functions.tests.h
  libcxx/test/std/containers/sequences/vector.bool/vector.bool.fmt/format.functions.tests.h
  libcxx/test/std/utilities/format/format.formattable/concept.formattable.compile.pass.cpp


Index: libcxx/test/std/utilities/format/format.formattable/concept.formattable.compile.pass.cpp
===================================================================
--- libcxx/test/std/utilities/format/format.formattable/concept.formattable.compile.pass.cpp
+++ libcxx/test/std/utilities/format/format.formattable/concept.formattable.compile.pass.cpp
@@ -199,6 +199,12 @@
 void test_P2286_vector_bool() {
   assert_is_formattable<Vector, CharT>();
   assert_is_formattable<typename Vector::reference, CharT>();
+
+  // The const_reference shall be a bool.
+  // However libc++ uses a __bit_const_reference<vector> when
+  // _LIBCPP_ABI_BITSET_VECTOR_BOOL_CONST_SUBSCRIPT_RETURN_BOOL is defined.
+  assert_is_formattable<const Vector&, CharT>();
+  assert_is_formattable<typename Vector::const_reference, CharT>();
 }
 
 // Tests for P2286 Formatting ranges
Index: libcxx/test/std/containers/sequences/vector.bool/vector.bool.fmt/format.functions.tests.h
===================================================================
--- libcxx/test/std/containers/sequences/vector.bool/vector.bool.fmt/format.functions.tests.h
+++ libcxx/test/std/containers/sequences/vector.bool/vector.bool.fmt/format.functions.tests.h
@@ -14,9 +14,7 @@
 #include "test_macros.h"
 
 template <class CharT, class TestFunction, class ExceptionTest>
-void format_tests(TestFunction check, ExceptionTest check_exception) {
-  std::vector input{true, true, false};
-
+void format_test_vector_bool(TestFunction check, ExceptionTest check_exception, auto&& input) {
   check(SV("[true, true, false]"), SV("{}"), input);
 
   // ***** underlying has no format-spec
@@ -113,4 +111,15 @@
   check_exception("Argument index out of bounds", SV("{:^^{}::>{}}"), input, 32);
 }
 
+template <class CharT, class TestFunction, class ExceptionTest>
+void format_tests(TestFunction check, ExceptionTest check_exception) {
+  format_test_vector_bool<CharT>(check, check_exception, std::vector{true, true, false});
+
+  // The const_reference shall be a bool.
+  // However libc++ uses a __bit_const_reference<vector> when
+  // _LIBCPP_ABI_BITSET_VECTOR_BOOL_CONST_SUBSCRIPT_RETURN_BOOL is defined.
+  const std::vector input{true, true, false};
+  format_test_vector_bool<CharT>(check, check_exception, input);
+}
+
 #endif // TEST_STD_CONTAINERS_SEQUENCES_VECTOR_BOOL_VECTOR_BOOL_FMT_FORMAT_FUNCTIONS_TESTS_H
Index: libcxx/test/std/containers/container.adaptors/container.adaptors.format/format.functions.tests.h
===================================================================
--- libcxx/test/std/containers/container.adaptors/container.adaptors.format/format.functions.tests.h
+++ libcxx/test/std/containers/container.adaptors/container.adaptors.format/format.functions.tests.h
@@ -399,8 +399,7 @@
 void test_bool(TestFunction check, ExceptionTest check_exception) {
   std::array input{true, true, false};
   test_bool<CharT>(check, check_exception, std::queue{input.begin(), input.end()});
-  // TODO FMT Use std::vector<bool> after it has been implemented.
-  test_bool<CharT>(check, check_exception, std::priority_queue<bool, std::deque<bool>>{input.begin(), input.end()});
+  test_bool<CharT>(check, check_exception, std::priority_queue{input.begin(), input.end()});
   test_bool<CharT>(check, check_exception, std::stack{input.begin(), input.end()});
 }
 
Index: libcxx/include/__bit_reference
===================================================================
--- libcxx/include/__bit_reference
+++ libcxx/include/__bit_reference
@@ -154,6 +154,8 @@
     friend typename _Cp::__self;
     friend class __bit_iterator<_Cp, true>;
 public:
+    using __container = typename _Cp::__self;
+
     _LIBCPP_INLINE_VISIBILITY
     __bit_const_reference(const __bit_const_reference&) = default;
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D144279.502371.patch
Type: text/x-patch
Size: 3757 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20230304/cf459545/attachment.bin>


More information about the libcxx-commits mailing list