public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/112607] New: <format>: _Normalize does not consider char_type for the basic_string_view case
@ 2023-11-18 16:28 hewillk at gmail dot com
  2023-11-18 18:09 ` [Bug libstdc++/112607] " redi at gcc dot gnu.org
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: hewillk at gmail dot com @ 2023-11-18 16:28 UTC (permalink / raw)
  To: gcc-bugs

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);
  }

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2023-11-28 22:32 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-18 16:28 [Bug libstdc++/112607] New: <format>: _Normalize does not consider char_type for the basic_string_view case hewillk at gmail dot com
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

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).