]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: Rename std::runtime_format for C++26 (P3953R3)
authorJonathan Wakely <jwakely@redhat.com>
Mon, 30 Mar 2026 11:13:39 +0000 (12:13 +0100)
committerJonathan Wakely <redi@gcc.gnu.org>
Wed, 1 Apr 2026 11:51:16 +0000 (12:51 +0100)
Last week in Croydon we approved P3953R3 to rename std::runtime_format
for C++26. The rationale is that with compile-time std::format, the name
std::runtime_format doesn't make sense. It's std::dynamic_format now
instead.

libstdc++-v3/ChangeLog:

* include/bits/chrono_io.h (__formatter_chrono::_S_empty_fs)
(__formatter_chrono::_M_C_y_Y, __formatter_chrono::_M_D_x)
(__formatter_chrono::_M_F, __formatter_chrono::_M_subsecs)
(__formatter_chrono_info::_M_format_to): Use
_Dynamic_format_string instead of _Runtime_format_string.
* include/bits/version.def (format): Bump value.
* include/bits/version.h: Regenerate.
* include/std/format (_Runtime_format_string): Rename to
_Dynamic_format_string.
(runtime_format): Rename to dynamic_format.
* include/std/print (println): Adjust comment to refer to
dynamic_format instead of runtime_format.
* testsuite/std/format/runtime_format.cc: Move to...
* testsuite/std/format/dynamic_format.cc: ...here.

Reviewed-by: Tomasz KamiƄski <tkaminsk@redhat.com>
libstdc++-v3/include/bits/chrono_io.h
libstdc++-v3/include/bits/version.def
libstdc++-v3/include/bits/version.h
libstdc++-v3/include/std/format
libstdc++-v3/include/std/print
libstdc++-v3/testsuite/std/format/dynamic_format.cc [moved from libstdc++-v3/testsuite/std/format/runtime_format.cc with 51% similarity]

index d152397891f21a39e2e0ca3ca57a5548663e7ae9..f5a0a65a48da62c641422b6399b5392432bc7ace 100644 (file)
@@ -885,9 +885,9 @@ namespace __format
       static constexpr const _CharT* _S_empty_spec = _S_chars + 18;
 
       [[__gnu__::__always_inline__]]
-      static _Runtime_format_string<_CharT>
+      static _Dynamic_format_string<_CharT>
       _S_empty_fs()
-      { return _Runtime_format_string<_CharT>(_S_empty_spec); }
+      { return _Dynamic_format_string<_CharT>(_S_empty_spec); }
 
       static constexpr const _CharT* _S_weekdays[]
       {
@@ -1321,7 +1321,7 @@ namespace __format
 
          if (__conv != 'y' && __ci >= 100) [[unlikely]]
            {
-             using _FmtStr = _Runtime_format_string<_CharT>;
+             using _FmtStr = _Dynamic_format_string<_CharT>;
              __string_view __fs = _S_minus_empty_spec + !__is_neg;
              __out = std::format_to(std::move(__out), _FmtStr(__fs),
                                     __conv == 'C' ? __ci : __yi);
@@ -1360,7 +1360,7 @@ namespace __format
 
          if (__mi >= 100 || __di >= 100) [[unlikely]]
            {
-             using _FmtStr = _Runtime_format_string<_CharT>;
+             using _FmtStr = _Dynamic_format_string<_CharT>;
              __string_view __fs = _GLIBCXX_WIDEN("{:02d}/{:02d}/{:02d}");
              __out = std::format_to(std::move(__out), _FmtStr(__fs),
                                     __mi, __di, __yi);
@@ -1416,7 +1416,7 @@ namespace __format
 
          if (__yi >= 10000 || __mi >= 100 || __di >= 100) [[unlikely]]
            {
-             using _FmtStr = _Runtime_format_string<_CharT>;
+             using _FmtStr = _Dynamic_format_string<_CharT>;
              __string_view __fs
                = _GLIBCXX_WIDEN("-{:04d}-{:02d}-{:02d}") + !__is_neg;
              __out = std::format_to(std::move(__out), _FmtStr(__fs),
@@ -1706,7 +1706,7 @@ namespace __format
          else if (__prec > __max_prec)
            __prec = __max_prec;
 
-         using _FmtStr = _Runtime_format_string<_CharT>;
+         using _FmtStr = _Dynamic_format_string<_CharT>;
          return std::format_to(__out, _FmtStr(_GLIBCXX_WIDEN("{0:0{1}}")),
                                __subs, __prec);
        }
@@ -2110,7 +2110,7 @@ namespace __format
         _Out
         _M_format_to(_Out __out, const chrono::sys_info& __si) const
         {
-          using _FmtStr = _Runtime_format_string<_CharT>;
+          using _FmtStr = _Dynamic_format_string<_CharT>;
           // 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.
index 8c9ec854d3b2686c650aeac0c05a75b7301a1ec0..434d38c8fbdf86f501f11054d566b73109c99a64 100644 (file)
@@ -1321,8 +1321,9 @@ ftms = {
   // 202305 P2757R3 Type checking format args
   // 202306 P2637R3 Member visit
   // 202311 P2918R2 Runtime format strings II
+  // 202603 P3953R3 Rename std::runtime_format
   values = {
-    v = 202311;
+    v = 202603;
     cxxmin = 26;
     hosted = yes;
   };
index 836aae02d773f925aa771fa0781574224a986f9e..bb2475087f1fcde485ac77a92bd6a29a9bba8018 100644 (file)
 
 #if !defined(__cpp_lib_format)
 # if (__cplusplus >  202302L) && _GLIBCXX_HOSTED
-#  define __glibcxx_format 202311L
+#  define __glibcxx_format 202603L
 #  if defined(__glibcxx_want_all) || defined(__glibcxx_want_format)
-#   define __cpp_lib_format 202311L
+#   define __cpp_lib_format 202603L
 #  endif
 # elif (__cplusplus >= 202002L) && _GLIBCXX_HOSTED
 #  define __glibcxx_format 202304L
index 555781bbd274973367330d53589bca8a8aa9a217..2bcd06822b75fa748a325210f506e7c08bff6676 100644 (file)
@@ -125,14 +125,14 @@ namespace __format
     using __format_context = basic_format_context<_Sink_iter<_CharT>, _CharT>;
 
   template<typename _CharT>
-    struct _Runtime_format_string
+    struct _Dynamic_format_string
     {
       [[__gnu__::__always_inline__]]
-      _Runtime_format_string(basic_string_view<_CharT> __s) noexcept
+      _Dynamic_format_string(basic_string_view<_CharT> __s) noexcept
       : _M_str(__s) { }
 
-      _Runtime_format_string(const _Runtime_format_string&) = delete;
-      void operator=(const _Runtime_format_string&) = delete;
+      _Dynamic_format_string(const _Dynamic_format_string&) = delete;
+      void operator=(const _Dynamic_format_string&) = delete;
 
     private:
       basic_string_view<_CharT> _M_str;
@@ -173,7 +173,7 @@ namespace __format
        basic_format_string(const _Tp& __s);
 
       [[__gnu__::__always_inline__]]
-      basic_format_string(__format::_Runtime_format_string<_CharT> __s) noexcept
+      basic_format_string(__format::_Dynamic_format_string<_CharT> __s) noexcept
       : _M_str(__s._M_str)
       { }
 
@@ -197,14 +197,14 @@ namespace __format
 
 #if __cpp_lib_format >= 202311L // >= C++26
   [[__gnu__::__always_inline__]]
-  inline __format::_Runtime_format_string<char>
-  runtime_format(string_view __fmt) noexcept
+  inline __format::_Dynamic_format_string<char>
+  dynamic_format(string_view __fmt) noexcept
   { return __fmt; }
 
 #ifdef _GLIBCXX_USE_WCHAR_T
   [[__gnu__::__always_inline__]]
-  inline __format::_Runtime_format_string<wchar_t>
-  runtime_format(wstring_view __fmt) noexcept
+  inline __format::_Dynamic_format_string<wchar_t>
+  dynamic_format(wstring_view __fmt) noexcept
   { return __fmt; }
 #endif
 #endif // C++26
index 6ffd9a4b1b3fec9750f66dff9fdc87f4e0d81c59..1b9e810419f0ef9afb41cf7319b0a7c2d0b5ee69 100644 (file)
@@ -352,7 +352,7 @@ namespace __format
        (enable_nonlocking_formatter_optimization<remove_cvref_t<_Args>> && ...);
 
       // The standard wants us to call
-      // print(stream, runtime_format(string(fmt.get()) + '\n'), args...)
+      // print(stream, dynamic_format(string(fmt.get()) + '\n'), args...)
       // here, but we can avoid that string concatenation in most cases,
       // and we know what that would call, so we can call that directly.
 
similarity index 51%
rename from libstdc++-v3/testsuite/std/format/runtime_format.cc
rename to libstdc++-v3/testsuite/std/format/dynamic_format.cc
index f2bfa5b434d2ea9c7343ac2b8ea4a7dbf812b52e..fde2555ccb2fe36129a98ec36b7bc4baef5539ab 100644 (file)
@@ -7,7 +7,7 @@ void
 test_char()
 {
   std::string fmt = "{}";
-  auto s = std::format(std::runtime_format(fmt), 123);
+  auto s = std::format(std::dynamic_format(fmt), 123);
   VERIFY( s == "123" );
 }
 
@@ -15,30 +15,30 @@ void
 test_wchar()
 {
   std::wstring fmt = L"{:#o}";
-  auto s = std::format(std::runtime_format(fmt), 456);
+  auto s = std::format(std::dynamic_format(fmt), 456);
   VERIFY( s == L"0710" );
 }
 
 void
 test_internal_api()
 {
-  // Using _Runtime_format_string directly works even in C++20 mode.
+  // Using _Dynamic_format_string directly works even in C++20 mode.
   // This can be used internally by libstdc++.
   std::string fmt = "{:#x}";
-  auto s = std::format(std::__format::_Runtime_format_string<char>(fmt), 789);
+  auto s = std::format(std::__format::_Dynamic_format_string<char>(fmt), 789);
   VERIFY( s == "0x315" );
 }
 
-static_assert( noexcept(std::format_string<>(std::runtime_format(""))) );
-static_assert( noexcept(std::wformat_string<>(std::runtime_format(L""))) );
-static_assert( noexcept(std::format_string<int>(std::runtime_format(""))) );
-static_assert( noexcept(std::wformat_string<char>(std::runtime_format(L""))) );
-// A format string can be constructed from the result of std::runtime_format
+static_assert( noexcept(std::format_string<>(std::dynamic_format(""))) );
+static_assert( noexcept(std::wformat_string<>(std::dynamic_format(L""))) );
+static_assert( noexcept(std::format_string<int>(std::dynamic_format(""))) );
+static_assert( noexcept(std::wformat_string<char>(std::dynamic_format(L""))) );
+// A format string can be constructed from the result of std::dynamic_format
 // using copy elision, but cannot be constructed from an xvalue.
 static_assert( !std::is_constructible_v<std::format_string<>,
-                                       decltype(std::runtime_format(""))&&> );
+                                       decltype(std::dynamic_format(""))&&> );
 static_assert( !std::is_constructible_v<std::wformat_string<>,
-                                       decltype(std::runtime_format(L""))&&> );
+                                       decltype(std::dynamic_format(L""))&&> );
 
 int main()
 {