diff options
author | Mark de Wever <koraq@xs4all.nl> | 2023-02-17 18:55:48 +0100 |
---|---|---|
committer | Mark de Wever <koraq@xs4all.nl> | 2023-03-07 19:10:26 +0100 |
commit | 24c251d94daaf6f36945445cac8562a1214bfaee (patch) | |
tree | 7864cc1c0f5b3db4546256c5632bb6c8b96a9a16 | |
parent | 9edef3e93de3f95ba2c6b4dcbb63ee02c6fa976e (diff) | |
download | llvm-24c251d94daaf6f36945445cac8562a1214bfaee.zip llvm-24c251d94daaf6f36945445cac8562a1214bfaee.tar.gz llvm-24c251d94daaf6f36945445cac8562a1214bfaee.tar.bz2 |
[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
3 files changed, 14 insertions, 3 deletions
diff --git a/libcxx/docs/Status/Cxx2bIssues.csv b/libcxx/docs/Status/Cxx2bIssues.csv index 324643b..1bdd4bf 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 baf062a..f893de6 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 ecec920..584ac2b 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()}}); } // |