]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: Fix incomplete rework of wchar_t support in std::format
authorJonathan Wakely <jwakely@redhat.com>
Fri, 18 Aug 2023 08:33:23 +0000 (09:33 +0100)
committerJonathan Wakely <jwakely@redhat.com>
Fri, 18 Aug 2023 08:36:38 +0000 (09:36 +0100)
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
libstdc++-v3/include/std/format

index 05caa64fb7c15beacb413f5f0c43b7090cf8f850..e16302baf8487c0d22b0d32d3e39c34a29794aea 100644 (file)
@@ -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,
index 13f700a10bfc27595ee82abd39e66012afea61cb..0b1ae8201af4a653b2c41e488984656e7e53f96e 100644 (file)
@@ -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