[libcxx-commits] [libcxx] 7e4639d - [libc++][format] Fixes formatting vector<bool>
Mark de Wever via libcxx-commits
libcxx-commits at lists.llvm.org
Sat Mar 4 04:59:54 PST 2023
Author: Mark de Wever
Date: 2023-03-04T13:59:49+01:00
New Revision: 7e4639d28f44dd8988ddb5fcc6063de96e3539cd
URL: https://github.com/llvm/llvm-project/commit/7e4639d28f44dd8988ddb5fcc6063de96e3539cd
DIFF: https://github.com/llvm/llvm-project/commit/7e4639d28f44dd8988ddb5fcc6063de96e3539cd.diff
LOG: [libc++][format] Fixes formatting vector<bool>
Formatting a const qualified vector<bool> fails to work on libc++. This
is due to our non-conforming type for vector<bool>::const_reference. The
type is a __bit_const_reference<vector> 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
Added:
Modified:
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
Removed:
################################################################################
diff --git a/libcxx/include/__bit_reference b/libcxx/include/__bit_reference
index 8b498cd16dc86..c66dc4a8e5e97 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 489de3a74096a..ecec920986e55 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 <class CharT, class TestFunction, class ExceptionTest>
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()});
}
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 32b68b85f85ab..4f17a990d4e0d 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 <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 @@ void format_tests(TestFunction check, ExceptionTest check_exception) {
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
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 1dd415abc38f3..0e4708e068ec4 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 <class CharT, class Vector>
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
More information about the libcxx-commits
mailing list