public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Jonathan Wakely <redi@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r14-5588] libstdc++: Check string value_type in std::make_format_args [PR112607] Date: Sat, 18 Nov 2023 21:44:36 +0000 (GMT) [thread overview] Message-ID: <20231118214436.590823858D35@sourceware.org> (raw) https://gcc.gnu.org/g:279e407a06cc676d8e6e0bb5755b0a804e05377c commit r14-5588-g279e407a06cc676d8e6e0bb5755b0a804e05377c Author: Jonathan Wakely <jwakely@redhat.com> Date: Sat Nov 18 20:56:35 2023 +0000 libstdc++: Check string value_type in std::make_format_args [PR112607] libstdc++-v3/ChangeLog: PR libstdc++/112607 * include/std/format (basic_format_arg::_S_to_arg_type): Check value_type for basic_string_view and basic_string specializations. * testsuite/std/format/arguments/112607.cc: New test. Diff: --- libstdc++-v3/include/std/format | 12 ++++++--- .../testsuite/std/format/arguments/112607.cc | 30 ++++++++++++++++++++++ 2 files changed, 38 insertions(+), 4 deletions(-) diff --git a/libstdc++-v3/include/std/format b/libstdc++-v3/include/std/format index 7c52cce5dbb..58cd310db4d 100644 --- a/libstdc++-v3/include/std/format +++ b/libstdc++-v3/include/std/format @@ -3220,10 +3220,14 @@ namespace __format return type_identity<__format::__float128_t>(); # endif #endif - else if constexpr (__is_specialization_of<_Td, basic_string_view>) - return type_identity<basic_string_view<_CharT>>(); - else if constexpr (__is_specialization_of<_Td, basic_string>) - return type_identity<basic_string_view<_CharT>>(); + else if constexpr (__is_specialization_of<_Td, basic_string_view> + || __is_specialization_of<_Td, basic_string>) + { + if constexpr (is_same_v<typename _Td::value_type, _CharT>) + return type_identity<basic_string_view<_CharT>>(); + else + return type_identity<handle>(); + } else if constexpr (is_same_v<decay_t<_Td>, const _CharT*>) return type_identity<const _CharT*>(); else if constexpr (is_same_v<decay_t<_Td>, _CharT*>) diff --git a/libstdc++-v3/testsuite/std/format/arguments/112607.cc b/libstdc++-v3/testsuite/std/format/arguments/112607.cc new file mode 100644 index 00000000000..19eec765ea5 --- /dev/null +++ b/libstdc++-v3/testsuite/std/format/arguments/112607.cc @@ -0,0 +1,30 @@ +// { dg-do compile { target c++20 } } + +// PR libstdc++/112607 +// _Normalize does not consider char_type for the basic_string_view case + +#include <format> + +template<typename T> +struct Alloc +{ + using value_type = T; + Alloc() = default; + template<typename U> + Alloc(const Alloc<U>&) { } + T* allocate(std::size_t); + void deallocate(T*, std::size_t); + bool operator==(const Alloc&) const; +}; + +template<typename C> +using String = std::basic_string<C, std::char_traits<C>, Alloc<C>>; + +template<> +struct std::formatter<String<wchar_t>> : std::formatter<std::string> { + auto format(const String<wchar_t>&, auto& ctx) const { + return std::formatter<std::string>::format(" ", ctx); + } +}; + +std::string str = std::format("{}", String<wchar_t>{});
reply other threads:[~2023-11-18 21:44 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20231118214436.590823858D35@sourceware.org \ --to=redi@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ --cc=libstdc++-cvs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).