public inbox for libstdc++-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-3323] libstdc++: Replace non-type-dependent uses of wchar_t in <format> and <chrono> Date: Fri, 18 Aug 2023 11:30:48 +0000 (GMT) [thread overview] Message-ID: <20230818113048.C28193858401@sourceware.org> (raw) https://gcc.gnu.org/g:6fabf8f25772bf7a7ff68a31a315cd91b86a186e commit r14-3323-g6fabf8f25772bf7a7ff68a31a315cd91b86a186e Author: Jonathan Wakely <jwakely@redhat.com> Date: Fri Aug 18 11:28:32 2023 +0100 libstdc++: Replace non-type-dependent uses of wchar_t in <format> and <chrono> This is one more piece of the rework to make wchar_t support in std::format depend on _GLIBCXX_USE_WCHAR_T. In <format> the __to_wstring_numeric function is called with arguments that aren't type-dependent, so a declaration needs to be available, or the calls need to be guarded by _GLIBCXX_USE_WCHAR_T. In <chrono> there is a similarly non-type-dependent call to std::format with a wchar_t format string, which is ill-formed when the wchar_t overloads of std::format are not declared. Use _GLIBCXX_WIDEN to make it type-dependent. libstdc++-v3/ChangeLog: * include/bits/chrono_io.h (operator<<): Make uses of wide strings with streams and std::format type-dependent on _CharT. * include/std/format [!_GLIBCXX_USE_WCHAR_T] Do not use __to_wstring_numeric. Diff: --- libstdc++-v3/include/bits/chrono_io.h | 17 ++++++----------- libstdc++-v3/include/std/format | 10 ++++++++-- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/libstdc++-v3/include/bits/chrono_io.h b/libstdc++-v3/include/bits/chrono_io.h index e16302baf848..d558802e7d86 100644 --- a/libstdc++-v3/include/bits/chrono_io.h +++ b/libstdc++-v3/include/bits/chrono_io.h @@ -2390,15 +2390,14 @@ namespace __detail __os2.imbue(__os.getloc()); __os2 << __wdi.weekday(); const auto __i = __wdi.index(); - if constexpr (is_same_v<_CharT, char>) - __os2 << std::format("[{}", __i); - else - __os2 << std::format(L"[{}", __i); - basic_string_view<_CharT> __s = _GLIBCXX_WIDEN(" is not a valid index]"); + basic_string_view<_CharT> __s + = _GLIBCXX_WIDEN("[ is not a valid index]"); + __os2 << __s[0]; + __os2 << std::format(_GLIBCXX_WIDEN("{}"), __i); if (__i >= 1 && __i <= 5) __os2 << __s.back(); else - __os2 << __s; + __os2 << __s.substr(1); __os << __os2.view(); return __os; } @@ -2457,11 +2456,7 @@ namespace __detail // As above, just write straight to a stringstream, as if by "{:L}/last" basic_stringstream<_CharT> __os2; __os2.imbue(__os.getloc()); - __os2 << __mdl.month(); - if constexpr (is_same_v<_CharT, char>) - __os2 << "/last"; - else - __os2 << L"/last"; + __os2 << __mdl.month() << _GLIBCXX_WIDEN("/last"); __os << __os2.view(); return __os; } diff --git a/libstdc++-v3/include/std/format b/libstdc++-v3/include/std/format index 0b1ae8201af4..648f847ad969 100644 --- a/libstdc++-v3/include/std/format +++ b/libstdc++-v3/include/std/format @@ -1142,13 +1142,15 @@ namespace __format basic_string_view<_CharT> __str; if constexpr (is_same_v<char, _CharT>) __str = __narrow_str; +#ifdef _GLIBCXX_USE_WCHAR_T else { size_t __n = __narrow_str.size(); auto __p = (_CharT*)__builtin_alloca(__n * sizeof(_CharT)); - __to_wstring_numeric(__narrow_str.data(), __n, __p); + std::__to_wstring_numeric(__narrow_str.data(), __n, __p); __str = {__p, __n}; } +#endif if (_M_spec._M_localized) { @@ -1624,11 +1626,13 @@ namespace __format basic_string_view<_CharT> __str; if constexpr (is_same_v<_CharT, char>) __str = __narrow_str; +#ifdef _GLIBCXX_USE_WCHAR_T else { __wstr = std::__to_wstring_numeric(__narrow_str); __str = __wstr; } +#endif if (_M_spec._M_localized) { @@ -2290,12 +2294,14 @@ namespace __format basic_string_view<_CharT> __str; if constexpr (is_same_v<_CharT, char>) __str = string_view(__buf, __n); +#ifdef _GLIBCXX_USE_WCHAR_T else { auto __p = (_CharT*)__builtin_alloca(__n * sizeof(_CharT)); - __to_wstring_numeric(__buf, __n, __p); + std::__to_wstring_numeric(__buf, __n, __p); __str = wstring_view(__p, __n); } +#endif #if _GLIBCXX_P2518R3 if (_M_spec._M_zero_fill)
reply other threads:[~2023-08-18 11:30 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=20230818113048.C28193858401@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).