]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
Update C++ tests and example.
authorBruno Haible <bruno@clisp.org>
Thu, 7 May 2026 23:17:18 +0000 (01:17 +0200)
committerBruno Haible <bruno@clisp.org>
Thu, 7 May 2026 23:17:18 +0000 (01:17 +0200)
* gettext-tools/examples/hello-c++20/hello.cc: Add comment regarding
runtime_format and dynamic_format.
(dynamic_format): Conditionally define to runtime_format.
(main): Use dynamic_format instead of runtime_format.
* gettext-tools/tests/lang-c++20: Conditionally define to runtime_format.
(main): Use dynamic_format instead of runtime_format.
* gettext-tools/tests/lang-c++26: Use dynamic_format instead of runtime_format.

gettext-tools/examples/hello-c++20/hello.cc
gettext-tools/tests/lang-c++20
gettext-tools/tests/lang-c++26

index 03828b55e3c51154795019806f11db2b53f91878..03f4a067e29325832275a38d99c6d74de0377d57 100644 (file)
 // <https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2023/p2918r2.html>,
 // uses a new symbol std::runtime_format, that
 //   - does not exist in g++ 13.3,
-//   - exists in g++ 14 or newer and clang++ 19 or newer, but requires the
+//   - exists in g++ 14..15 and clang++ 19..22, but requires the
 //     option -std=gnu++26.
+// This replacement API was then incompatibly modified in
+// <https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2026/p3953r3.html>,
+// renaming std::runtime_format to std::dynamic_format.  It is supported in
+// g++ 16 or newer and clang++ 23 or newer.
 
 #include <format>
 #include <iostream>
 using namespace std;
+#if __cpp_lib_format > 202106L && __cpp_lib_format < 202603L
+# define dynamic_format runtime_format
+#endif
 
 // Get setlocale() declaration.
 #include <locale.h>
@@ -50,7 +57,7 @@ main ()
   cout << vformat (_("This program is running as process number {:d}."),
                    make_format_args (getpid ()))
 #else
-  cout << format (runtime_format (_("This program is running as process number {:d}.")),
+  cout << format (dynamic_format (_("This program is running as process number {:d}.")),
                   getpid ())
 #endif
        << endl;
index 07c641d8135a65ac998624a6eee996f6b5dccb0b..97ba6a4b5aca90a4df08b58125ae90f7cc9549c5 100755 (executable)
@@ -29,8 +29,11 @@ cat <<\EOF > test.cc
 using std::vformat;
 using std::make_format_args;
 #else
+# if __cpp_lib_format < 202603L
+#  define dynamic_format runtime_format
+# endif
 using std::format;
-using std::runtime_format;
+using std::dynamic_format;
 #endif
 EOF
 if ${CXX} ${CXXFLAGS} ${CPPFLAGS} -c test.cc 2>/dev/null; then
@@ -51,6 +54,9 @@ cat <<\EOF > prog.cc
 #include <format>
 #include <iostream>
 using namespace std;
+#if __cpp_lib_format > 202106L && __cpp_lib_format < 202603L
+# define dynamic_format runtime_format
+#endif
 
 #include <libintl.h>
 #include <locale.h>
@@ -76,7 +82,7 @@ int main (int argc, char *argv[])
   cout << vformat (ngettext ("a piece of cake", "{} pieces of cake", n),
                    make_format_args (n))
 #else
-  cout << format (runtime_format (ngettext ("a piece of cake", "{} pieces of cake", n)),
+  cout << format (dynamic_format (ngettext ("a piece of cake", "{} pieces of cake", n)),
                   n)
 #endif
        << endl;
@@ -84,7 +90,7 @@ int main (int argc, char *argv[])
 #if __cpp_lib_format <= 202106L
   cout << vformat (_("{} is replaced by {}."), make_format_args ("FF", "EUR"))
 #else
-  cout << format (runtime_format (_("{} is replaced by {}.")), "FF", "EUR")
+  cout << format (dynamic_format (_("{} is replaced by {}.")), "FF", "EUR")
 #endif
        << endl;
 }
index 31ac6967a9a035640672c6640b220a96bccca41b..e292431ebc8d74bdabbc74512194917c74eb6451 100755 (executable)
@@ -19,7 +19,7 @@ test "${CXX}" != "no" || {
 cat <<\EOF > test.cc
 #include <format>
 using std::format;
-using std::runtime_format;
+using std::dynamic_format;
 EOF
 if ${CXX} ${CXXFLAGS} ${CPPFLAGS} -c test.cc 2>/dev/null; then
   CXX26=
@@ -58,11 +58,11 @@ int main (int argc, char *argv[])
 
   cout << _("'Your command, please?', asked the waiter.") << endl;
 
-  cout << format (runtime_format (ngettext ("a piece of cake", "{} pieces of cake", n)),
+  cout << format (dynamic_format (ngettext ("a piece of cake", "{} pieces of cake", n)),
                   n)
        << endl;
 
-  cout << format (runtime_format (_("{} is replaced by {}.")), "FF", "EUR")
+  cout << format (dynamic_format (_("{} is replaced by {}.")), "FF", "EUR")
        << endl;
 }
 EOF