Formatting sys_info as wchar_t require widening of the abbrev (zone) member.
To support that we reuse the existing code in support for '%Z' specifier, for
local_time_format, and produce output using singe format call with
"[{0:%F %T},{1:%F %T},{2:%T},{3:%Q%q},{0:%Z}]" format string.
As noted in the comment, produced output is localled independed, as it does
not contain decimal separtors.

For sys_info, the outputed literals are widended using _GLIBCXX_WIDEN, except
opening and closing brackets, that are fetched from __format::_Separators.

        PR libstdc++/120565

libstdc++-v3/ChangeLog:

        * include/bits/chrono_io.h
        (operator<<(basic_ostream<_CharT, _Traits>&, const sys_info&))
        (operator<<(basic_ostream<_CharT, _Traits>&, const local_info&)):
        Support wchar_t as _CharT.
        * testsuite/std/time/format/empty_spec.cc: Instantiated test_infos for
        wchar_t and increase timeout.
---
This patch is on top of following patch that add test cases covering local_info:
"[PATCH v2] libstdc++: Test for formatting with empty spec for local_info and 
sys_info."
The test timeout-factor is now 5, so perfect test for testing compile-time 
reduction
for chrono. This is why I haven't separated it in multiple-files.

Tested both combined on x86_64-linux. OK for trunk?

 libstdc++-v3/include/bits/chrono_io.h         | 23 +++++++++++--------
 .../testsuite/std/time/format/empty_spec.cc   |  6 ++---
 2 files changed, 17 insertions(+), 12 deletions(-)

diff --git a/libstdc++-v3/include/bits/chrono_io.h 
b/libstdc++-v3/include/bits/chrono_io.h
index 9711a83cebe..c5c5e4bae53 100644
--- a/libstdc++-v3/include/bits/chrono_io.h
+++ b/libstdc++-v3/include/bits/chrono_io.h
@@ -2944,9 +2944,14 @@ namespace __detail
     basic_ostream<_CharT, _Traits>&
     operator<<(basic_ostream<_CharT, _Traits>& __os, const sys_info& __i)
     {
-      __os << '[' << __i.begin << ',' << __i.end
-          << ',' << hh_mm_ss(__i.offset) << ',' << __i.save
-          << ',' << __i.abbrev << ']';
+      // n.b. only decimal separator is locale dependent for specifiers
+      // used below, as sys_info uses seconds and minutes duration, the
+      // output is locale-independent.
+      constexpr auto* __fs 
+       = _GLIBCXX_WIDEN("[{0:%F %T},{1:%F %T},{2:%T},{3:%Q%q},{0:%Z}]");
+      local_seconds __lb(__i.begin.time_since_epoch());
+      __os << std::format(__fs, local_time_format(__lb, &__i.abbrev),
+                         __i.end, __i.offset, __i.save);
       return __os;
     }
 
@@ -2955,19 +2960,19 @@ namespace __detail
     basic_ostream<_CharT, _Traits>&
     operator<<(basic_ostream<_CharT, _Traits>& __os, const local_info& __li)
     {
-      __os << '[';
+      __os << __format::_Separators<_CharT>::_S_squares()[0];
       if (__li.result == local_info::unique)
        __os << __li.first;
       else
        {
          if (__li.result == local_info::nonexistent)
-           __os << "nonexistent";
+           __os << _GLIBCXX_WIDEN("nonexistent");
          else
-           __os << "ambiguous";
-         __os << " local time between " << __li.first;
-         __os << " and " << __li.second;
+           __os << _GLIBCXX_WIDEN("ambiguous");
+         __os << _GLIBCXX_WIDEN(" local time between ") << __li.first;
+         __os << _GLIBCXX_WIDEN(" and ") << __li.second;
        }
-      __os << ']';
+      __os << __format::_Separators<_CharT>::_S_squares()[1];
       return __os;
     }
 
diff --git a/libstdc++-v3/testsuite/std/time/format/empty_spec.cc 
b/libstdc++-v3/testsuite/std/time/format/empty_spec.cc
index 661712f1238..7af00e46861 100644
--- a/libstdc++-v3/testsuite/std/time/format/empty_spec.cc
+++ b/libstdc++-v3/testsuite/std/time/format/empty_spec.cc
@@ -842,14 +842,14 @@ test_all()
   test_durations<CharT>();
   test_calendar<CharT>();
   test_time_points<CharT>();
+#if _GLIBCXX_USE_CXX11_ABI || !_GLIBCXX_USE_DUAL_ABI
+  test_infos<CharT>();
+#endif
 }
 
 int main()
 {
   test_all<char>();
-#if _GLIBCXX_USE_CXX11_ABI || !_GLIBCXX_USE_DUAL_ABI
-  test_infos<char>();
-#endif
 
 #ifdef _GLIBCXX_USE_WCHAR_T
   test_all<wchar_t>();
-- 
2.49.0

Reply via email to