public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "hewillk at gmail dot com" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/112607] New: <format>: _Normalize does not consider char_type for the basic_string_view case Date: Sat, 18 Nov 2023 16:28:56 +0000 [thread overview] Message-ID: <bug-112607-4@http.gcc.gnu.org/bugzilla/> (raw) https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112607 Bug ID: 112607 Summary: <format>: _Normalize does not consider char_type for the basic_string_view case Product: gcc Version: 14.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: libstdc++ Assignee: unassigned at gcc dot gnu.org Reporter: hewillk at gmail dot com Target Milestone: --- When T in basic_format_arg(T& v) is a specialization of basic_string_view or basic_string, format#arg-6.8 indicates: otherwise, if TD is a specialization of basic_string_view or basic_string and TD::value_type is char_type, initializes value with basic_string_view<char_type>(v.data(), v.size()); We need to consider TD::value_type is char_type. However, libstd++ only uses __is_specialization_of to detect whether T is a specialization of basic_string_view or basic_string (format#L3118-L3121): 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>>(); This causes basic_format_arg to incorrectly use wstring_view to initialize string_view when customizing std::wstring. https://godbolt.org/z/6Kd16z8qK #include <format> template<> struct std::formatter<std::wstring> : std::formatter<std::string> { auto format(const std::wstring& obj, auto& ctx) const { return std::formatter<std::string>::format(" ", ctx); } }; int main(){ std::wstring wstr; std::string str = std::format("{}", wstr); }
next reply other threads:[~2023-11-18 16:28 UTC|newest] Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top 2023-11-18 16:28 hewillk at gmail dot com [this message] 2023-11-18 18:09 ` [Bug libstdc++/112607] " redi at gcc dot gnu.org 2023-11-18 18:15 ` redi at gcc dot gnu.org 2023-11-18 18:20 ` redi at gcc dot gnu.org 2023-11-18 19:42 ` redi at gcc dot gnu.org 2023-11-18 21:44 ` cvs-commit at gcc dot gnu.org 2023-11-18 21:52 ` redi at gcc dot gnu.org 2023-11-28 22:30 ` cvs-commit at gcc dot gnu.org 2023-11-28 22:32 ` redi at gcc dot gnu.org
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=bug-112607-4@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@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).