[libcxx-commits] [libcxx] 24c251d - [libc++][format] Addresses LWG3881.
Mark de Wever via libcxx-commits
libcxx-commits at lists.llvm.org
Tue Mar 7 10:10:32 PST 2023
Author: Mark de Wever
Date: 2023-03-07T19:10:26+01:00
New Revision: 24c251d94daaf6f36945445cac8562a1214bfaee
URL: https://github.com/llvm/llvm-project/commit/24c251d94daaf6f36945445cac8562a1214bfaee
DIFF: https://github.com/llvm/llvm-project/commit/24c251d94daaf6f36945445cac8562a1214bfaee.diff
LOG: [libc++][format] Addresses LWG3881.
LWG3881 Incorrect formatting of container adapters backed by std::string
Reviewed By: #libc, ldionne
Differential Revision: https://reviews.llvm.org/D144277
Added:
Modified:
libcxx/docs/Status/Cxx2bIssues.csv
libcxx/include/__format/container_adaptor.h
libcxx/test/std/containers/container.adaptors/container.adaptors.format/format.functions.tests.h
Removed:
################################################################################
diff --git a/libcxx/docs/Status/Cxx2bIssues.csv b/libcxx/docs/Status/Cxx2bIssues.csv
index 324643b96a81..1bdd4bf1a857 100644
--- a/libcxx/docs/Status/Cxx2bIssues.csv
+++ b/libcxx/docs/Status/Cxx2bIssues.csv
@@ -305,6 +305,6 @@
"`3878 <https://wg21.link/LWG3878>`__","import ``std;`` should guarantee initialization of standard iostreams objects","February 2023","","",""
"`3879 <https://wg21.link/LWG3879>`__","``erase_if`` for ``flat_{,multi}set`` is incorrectly specified","February 2023","","",""
"`3880 <https://wg21.link/LWG3880>`__","Clarify ``operator+=`` complexity for ``{chunk,stride}_view::iterator``","February 2023","","","|ranges|"
-"`3881 <https://wg21.link/LWG3881>`__","Incorrect formatting of container adapters backed by ``std::string``","February 2023","","","|format|"
+"`3881 <https://wg21.link/LWG3881>`__","Incorrect formatting of container adapters backed by ``std::string``","February 2023","|Complete|","17.0","|format|"
"","","","","",""
"`3343 <https://wg21.link/LWG3343>`__","Ordering of calls to ``unlock()`` and ``notify_all()`` in Effects element of ``notify_all_at_thread_exit()`` should be reversed","Not Yet Adopted","|Complete|","16.0",""
diff --git a/libcxx/include/__format/container_adaptor.h b/libcxx/include/__format/container_adaptor.h
index baf062af1a80..f893de620f6a 100644
--- a/libcxx/include/__format/container_adaptor.h
+++ b/libcxx/include/__format/container_adaptor.h
@@ -19,6 +19,8 @@
#include <__format/concepts.h>
#include <__format/formatter.h>
#include <__format/range_default_formatter.h>
+#include <__ranges/all.h>
+#include <__ranges/ref_view.h>
#include <queue>
#include <stack>
@@ -35,8 +37,9 @@ _LIBCPP_BEGIN_NAMESPACE_STD
template <class _Adaptor, class _CharT>
struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT __formatter_container_adaptor {
private:
- using __maybe_const_adaptor = __fmt_maybe_const<_Adaptor, _CharT>;
- formatter<typename _Adaptor::container_type, _CharT> __underlying_;
+ using __maybe_const_container = __fmt_maybe_const<typename _Adaptor::container_type, _CharT>;
+ using __maybe_const_adaptor = __maybe_const<is_const_v<__maybe_const_container>, _Adaptor>;
+ formatter<ranges::ref_view<__maybe_const_container>, _CharT> __underlying_;
public:
template <class _ParseContext>
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 ecec920986e5..584ac2b2d8d1 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
@@ -250,6 +250,14 @@ void test_char(TestFunction check, ExceptionTest check_exception) {
test_char_escaped_string<CharT>(
check, check_exception, std::priority_queue{input.begin(), input.end(), std::greater{}});
test_char_escaped_string<CharT>(check, check_exception, std::stack{input.begin(), input.end()});
+
+ // LWG3881 fixes formatting container adaptors backed by a std::string.
+ test_char_default<CharT>(check, check_exception, std::queue{std::basic_string<CharT>{input.begin(), input.end()}});
+ test_char_default<CharT>(
+ check,
+ check_exception,
+ std::priority_queue{std::greater{}, std::basic_string<CharT>{input.begin(), input.end()}});
+ test_char_default<CharT>(check, check_exception, std::stack{std::basic_string<CharT>{input.begin(), input.end()}});
}
//
More information about the libcxx-commits
mailing list