From: Bruno Haible Date: Thu, 7 May 2026 23:17:18 +0000 (+0200) Subject: Update C++ tests and example. X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ebdde485544c6891bf39b93658c51646dcfba776;p=thirdparty%2Fgettext.git Update C++ tests and example. * 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. --- diff --git a/gettext-tools/examples/hello-c++20/hello.cc b/gettext-tools/examples/hello-c++20/hello.cc index 03828b55e..03f4a067e 100644 --- a/gettext-tools/examples/hello-c++20/hello.cc +++ b/gettext-tools/examples/hello-c++20/hello.cc @@ -13,12 +13,19 @@ // , // 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 +// , +// renaming std::runtime_format to std::dynamic_format. It is supported in +// g++ 16 or newer and clang++ 23 or newer. #include #include using namespace std; +#if __cpp_lib_format > 202106L && __cpp_lib_format < 202603L +# define dynamic_format runtime_format +#endif // Get setlocale() declaration. #include @@ -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; diff --git a/gettext-tools/tests/lang-c++20 b/gettext-tools/tests/lang-c++20 index 07c641d81..97ba6a4b5 100755 --- a/gettext-tools/tests/lang-c++20 +++ b/gettext-tools/tests/lang-c++20 @@ -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 #include using namespace std; +#if __cpp_lib_format > 202106L && __cpp_lib_format < 202603L +# define dynamic_format runtime_format +#endif #include #include @@ -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; } diff --git a/gettext-tools/tests/lang-c++26 b/gettext-tools/tests/lang-c++26 index 31ac6967a..e292431eb 100755 --- a/gettext-tools/tests/lang-c++26 +++ b/gettext-tools/tests/lang-c++26 @@ -19,7 +19,7 @@ test "${CXX}" != "no" || { cat <<\EOF > test.cc #include 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