public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH 1/3] libstdc++: Use formatting locale for std::time_put formats
@ 2025-03-20  9:26 Jonathan Wakely
  2025-03-20  9:26 ` [PATCH 2/3] libstdc++: Fix localized D_T_FMT %c formatting for <chrono> [PR117214] Jonathan Wakely
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Jonathan Wakely @ 2025-03-20  9:26 UTC (permalink / raw)
  To: gcc-patches; +Cc: libstdc++

When using std::time_put to format a chrono value, we should imbue the
formatting locale into the stream. This ensures that when
std::time_put::do_put uses a ctype or __timepunct facet from the locale,
it gets the correct facets.

libstdc++-v3/ChangeLog:

	* include/bits/chrono_io.h (__formatter_chrono::_M_locale_fmt):
	Imbue locale into ostringstream.
---

This doesn't cause a problem with any existing formatters, but is needed
for the next patches in this series. I'll try to come up with a
standalone testcase that depends on this fix (involving a custom facet
derived from std::time_put which uses the locale in its do_put).

Tested x86_64-linux.

 libstdc++-v3/include/bits/chrono_io.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/libstdc++-v3/include/bits/chrono_io.h b/libstdc++-v3/include/bits/chrono_io.h
index c16b555df29..55ebd4ee061 100644
--- a/libstdc++-v3/include/bits/chrono_io.h
+++ b/libstdc++-v3/include/bits/chrono_io.h
@@ -1697,6 +1697,7 @@ namespace __format
 		      char __fmt, char __mod) const
 	{
 	  basic_ostringstream<_CharT> __os;
+	  __os.imbue(__loc);
 	  const auto& __tp = use_facet<time_put<_CharT>>(__loc);
 	  __tp.put(__os, __os, _S_space, &__tm, __fmt, __mod);
 	  if (__os)
-- 
2.48.1


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

end of thread, other threads:[~2025-03-21 12:34 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-03-20  9:26 [PATCH 1/3] libstdc++: Use formatting locale for std::time_put formats Jonathan Wakely
2025-03-20  9:26 ` [PATCH 2/3] libstdc++: Fix localized D_T_FMT %c formatting for <chrono> [PR117214] Jonathan Wakely
2025-03-21 10:51   ` Tomasz Kaminski
2025-03-20  9:26 ` [PATCH 3/3] libstdc++: Fix localized %c formatting for non-UTC times [PR117214] Jonathan Wakely
2025-03-21 12:24   ` Tomasz Kaminski
2025-03-21 12:33     ` Jonathan Wakely
2025-03-20 16:13 ` [PATCH v2 1/3] libstdc++: Use formatting locale for std::time_put formats Jonathan Wakely
2025-03-20 16:20   ` Jonathan Wakely
2025-03-21  9:47     ` Tomasz Kaminski
2025-03-21 10:58       ` Jonathan Wakely

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