From: Jonathan Wakely <jwakely@redhat.com>
To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org
Subject: [committed] libstdc++: Fix incomplete rework of wchar_t support in std::format
Date: Fri, 18 Aug 2023 09:44:16 +0100 [thread overview]
Message-ID: <20230818084437.1297460-1-jwakely@redhat.com> (raw)
In-Reply-To: <20230817203118.1131359-1-jwakely@redhat.com>
Tested x86_64-linux. Pushed to trunk.
-- >8 --
r14-3300-g023a62b77f999b left make_wformat_args and some uses of
std::wformat_context unguarded by _GLIBCXX_USE_WCHAR_T.
libstdc++-v3/ChangeLog:
* include/bits/chrono_io.h (operator<<): Use __format_context.
* include/std/format (__format::__format_context): New alias
template.
[!_GLIBCXX_USE_WCHAR_T] (wformat_args, make_wformat_arg):
Disable.
---
libstdc++-v3/include/bits/chrono_io.h | 15 +++++----------
libstdc++-v3/include/std/format | 13 +++++++++----
2 files changed, 14 insertions(+), 14 deletions(-)
diff --git a/libstdc++-v3/include/bits/chrono_io.h b/libstdc++-v3/include/bits/chrono_io.h
index 05caa64fb7c..e16302baf84 100644
--- a/libstdc++-v3/include/bits/chrono_io.h
+++ b/libstdc++-v3/include/bits/chrono_io.h
@@ -2263,8 +2263,7 @@ namespace __detail
inline basic_ostream<_CharT, _Traits>&
operator<<(basic_ostream<_CharT, _Traits>& __os, const day& __d)
{
- using _Ctx = __conditional_t<is_same_v<_CharT, char>,
- format_context, wformat_context>;
+ using _Ctx = __format::__format_context<_CharT>;
using _Str = basic_string_view<_CharT>;
_Str __s = _GLIBCXX_WIDEN("{:02d} is not a valid day");
if (__d.ok())
@@ -2291,8 +2290,7 @@ namespace __detail
inline basic_ostream<_CharT, _Traits>&
operator<<(basic_ostream<_CharT, _Traits>& __os, const month& __m)
{
- using _Ctx = __conditional_t<is_same_v<_CharT, char>,
- format_context, wformat_context>;
+ using _Ctx = __format::__format_context<_CharT>;
using _Str = basic_string_view<_CharT>;
_Str __s = _GLIBCXX_WIDEN("{:L%b}{} is not a valid month");
if (__m.ok())
@@ -2322,8 +2320,7 @@ namespace __detail
inline basic_ostream<_CharT, _Traits>&
operator<<(basic_ostream<_CharT, _Traits>& __os, const year& __y)
{
- using _Ctx = __conditional_t<is_same_v<_CharT, char>,
- format_context, wformat_context>;
+ using _Ctx = __format::__format_context<_CharT>;
using _Str = basic_string_view<_CharT>;
_Str __s = _GLIBCXX_WIDEN("-{:04d} is not a valid year");
if (__y.ok())
@@ -2355,8 +2352,7 @@ namespace __detail
inline basic_ostream<_CharT, _Traits>&
operator<<(basic_ostream<_CharT, _Traits>& __os, const weekday& __wd)
{
- using _Ctx = __conditional_t<is_same_v<_CharT, char>,
- format_context, wformat_context>;
+ using _Ctx = __format::__format_context<_CharT>;
using _Str = basic_string_view<_CharT>;
_Str __s = _GLIBCXX_WIDEN("{:L%a}{} is not a valid weekday");
if (__wd.ok())
@@ -2544,8 +2540,7 @@ namespace __detail
operator<<(basic_ostream<_CharT, _Traits>& __os,
const year_month_day& __ymd)
{
- using _Ctx = __conditional_t<is_same_v<_CharT, char>,
- format_context, wformat_context>;
+ using _Ctx = __format::__format_context<_CharT>;
using _Str = basic_string_view<_CharT>;
_Str __s = _GLIBCXX_WIDEN("{:%F} is not a valid date");
__os << std::vformat(__ymd.ok() ? __s.substr(0, 5) : __s,
diff --git a/libstdc++-v3/include/std/format b/libstdc++-v3/include/std/format
index 13f700a10bf..0b1ae8201af 100644
--- a/libstdc++-v3/include/std/format
+++ b/libstdc++-v3/include/std/format
@@ -74,20 +74,23 @@ namespace __format
// Output iterator that writes to a type-erase character sink.
template<typename _CharT>
class _Sink_iter;
+
+ template<typename _CharT>
+ using __format_context = basic_format_context<_Sink_iter<_CharT>, _CharT>;
} // namespace __format
/// @endcond
- using format_context
- = basic_format_context<__format::_Sink_iter<char>, char>;
+ using format_context = __format::__format_context<char>;
#ifdef _GLIBCXX_USE_WCHAR_T
- using wformat_context
- = basic_format_context<__format::_Sink_iter<wchar_t>, wchar_t>;
+ using wformat_context = __format::__format_context<wchar_t>;
#endif
// [format.args], class template basic_format_args
template<typename _Context> class basic_format_args;
using format_args = basic_format_args<format_context>;
+#ifdef _GLIBCXX_USE_WCHAR_T
using wformat_args = basic_format_args<wformat_context>;
+#endif
// [format.arguments], arguments
// [format.arg], class template basic_format_arg
@@ -3505,12 +3508,14 @@ namespace __format
return _Store(__fmt_args...);
}
+#ifdef _GLIBCXX_USE_WCHAR_T
/// Capture formatting arguments for use by `std::vformat` (for wide output).
template<typename... _Args>
[[nodiscard,__gnu__::__always_inline__]]
inline auto
make_wformat_args(_Args&&... __args) noexcept
{ return std::make_format_args<wformat_context>(__args...); }
+#endif
/// @cond undocumented
namespace __format
--
2.41.0
next prev parent reply other threads:[~2023-08-18 8:44 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-17 20:31 [committed] libstdc++: Rework std::format support for wchar_t Jonathan Wakely
2023-08-18 8:44 ` Jonathan Wakely [this message]
2023-08-18 11:31 ` [committed] libstdc++: Replace non-type-dependent uses of wchar_t in <format> and <chrono> Jonathan Wakely
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=20230818084437.1297460-1-jwakely@redhat.com \
--to=jwakely@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=libstdc++@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: link
Be 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).