From 7e4639d28f44dd8988ddb5fcc6063de96e3539cd Mon Sep 17 00:00:00 2001 From: Mark de Wever Date: Fri, 17 Feb 2023 18:55:48 +0100 Subject: [PATCH] [libc++][format] Fixes formatting vector Formatting a const qualified vector fails to work on libc++. This is due to our non-conforming type for vector::const_reference. The type is a __bit_const_reference instead of a bool. (This is fixed in ABI v2.) This fixes this formatter and enables the test written for it. Reviewed By: #libc, ldionne Differential Revision: https://reviews.llvm.org/D144279 --- libcxx/include/__bit_reference | 2 ++ .../container.adaptors.format/format.functions.tests.h | 3 +-- .../vector.bool/vector.bool.fmt/format.functions.tests.h | 15 ++++++++++++--- .../concept.formattable.compile.pass.cpp | 6 ++++++ 4 files changed, 21 insertions(+), 5 deletions(-) diff --git a/libcxx/include/__bit_reference b/libcxx/include/__bit_reference index 8b498cd..c66dc4a 100644 --- a/libcxx/include/__bit_reference +++ b/libcxx/include/__bit_reference @@ -154,6 +154,8 @@ class __bit_const_reference 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; diff --git a/libcxx/test/std/containers/container.adaptors/container.adaptors.format/format.functions.tests.h b/libcxx/test/std/containers/container.adaptors/container.adaptors.format/format.functions.tests.h index 489de3a..ecec920 100644 --- a/libcxx/test/std/containers/container.adaptors/container.adaptors.format/format.functions.tests.h +++ b/libcxx/test/std/containers/container.adaptors/container.adaptors.format/format.functions.tests.h @@ -399,8 +399,7 @@ template void test_bool(TestFunction check, ExceptionTest check_exception) { std::array input{true, true, false}; test_bool(check, check_exception, std::queue{input.begin(), input.end()}); - // TODO FMT Use std::vector after it has been implemented. - test_bool(check, check_exception, std::priority_queue>{input.begin(), input.end()}); + test_bool(check, check_exception, std::priority_queue{input.begin(), input.end()}); test_bool(check, check_exception, std::stack{input.begin(), input.end()}); } diff --git a/libcxx/test/std/containers/sequences/vector.bool/vector.bool.fmt/format.functions.tests.h b/libcxx/test/std/containers/sequences/vector.bool/vector.bool.fmt/format.functions.tests.h index 32b68b8..4f17a99 100644 --- a/libcxx/test/std/containers/sequences/vector.bool/vector.bool.fmt/format.functions.tests.h +++ b/libcxx/test/std/containers/sequences/vector.bool/vector.bool.fmt/format.functions.tests.h @@ -14,9 +14,7 @@ #include "test_macros.h" template -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 @@ void format_tests(TestFunction check, ExceptionTest check_exception) { check_exception("Argument index out of bounds", SV("{:^^{}::>{}}"), input, 32); } +template +void format_tests(TestFunction check, ExceptionTest check_exception) { + format_test_vector_bool(check, check_exception, std::vector{true, true, false}); + + // The const_reference shall be a bool. + // However libc++ uses a __bit_const_reference when + // _LIBCPP_ABI_BITSET_VECTOR_BOOL_CONST_SUBSCRIPT_RETURN_BOOL is defined. + const std::vector input{true, true, false}; + format_test_vector_bool(check, check_exception, input); +} + #endif // TEST_STD_CONTAINERS_SEQUENCES_VECTOR_BOOL_VECTOR_BOOL_FMT_FORMAT_FUNCTIONS_TESTS_H diff --git a/libcxx/test/std/utilities/format/format.formattable/concept.formattable.compile.pass.cpp b/libcxx/test/std/utilities/format/format.formattable/concept.formattable.compile.pass.cpp index 1dd415a..0e4708e 100644 --- a/libcxx/test/std/utilities/format/format.formattable/concept.formattable.compile.pass.cpp +++ b/libcxx/test/std/utilities/format/format.formattable/concept.formattable.compile.pass.cpp @@ -199,6 +199,12 @@ template void test_P2286_vector_bool() { assert_is_formattable(); assert_is_formattable(); + + // The const_reference shall be a bool. + // However libc++ uses a __bit_const_reference when + // _LIBCPP_ABI_BITSET_VECTOR_BOOL_CONST_SUBSCRIPT_RETURN_BOOL is defined. + assert_is_formattable(); + assert_is_formattable(); } // Tests for P2286 Formatting ranges -- 2.7.4