]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
tests: Fix lang-c++20 failure with g++ >= 14 or clang++ >= 19.
authorBruno Haible <bruno@clisp.org>
Mon, 2 Dec 2024 11:09:40 +0000 (12:09 +0100)
committerBruno Haible <bruno@clisp.org>
Mon, 2 Dec 2024 11:09:40 +0000 (12:09 +0100)
* gettext-tools/tests/lang-c++20: Support newer C++ versions. Try option
-std=gnu++26, necessary for newer C++ versions.

gettext-tools/tests/lang-c++20

index 3163d71a86a60ea6ca95f9cd94bd8a4383dd3ea1..ee0693e0cb03e97a130cbeb1d35df935b80f06dd 100755 (executable)
@@ -13,6 +13,9 @@
 # https://discourse.llvm.org/t/std-format-not-available-in-libc-15/66137
 # https://stackoverflow.com/questions/71777564/
 
+# This test also fails with g++ 13.3. See the comments in
+# gettext-tools/examples/hello-c++20/hello.cc.
+
 # Test whether a C++ compiler is found.
 test "${CXX}" != "no" || {
   echo "Skipping test: no C++ compiler found"
@@ -22,13 +25,20 @@ test "${CXX}" != "no" || {
 # Try to find compiler option for ISO C++ 20 support.
 cat <<\EOF > test.cc
 #include <format>
+#if __cpp_lib_format <= 202106L
 using std::vformat;
 using std::make_format_args;
+#else
+using std::format;
+using std::runtime_format;
+#endif
 EOF
 if ${CXX} ${CXXFLAGS} ${CPPFLAGS} -c test.cc 2>/dev/null; then
   CXX20=
 elif ${CXX} ${CXXFLAGS} -std=gnu++20 ${CPPFLAGS} -c test.cc 2>/dev/null; then
   CXX20='-std=gnu++20'
+elif ${CXX} ${CXXFLAGS} -std=gnu++26 ${CPPFLAGS} -c test.cc 2>/dev/null; then
+  CXX20='-std=gnu++26'
 else
   echo "Skipping test: C++ compiler does not support ISO C++ 20"
   Exit 77
@@ -62,11 +72,20 @@ int main (int argc, char *argv[])
 
   cout << _("'Your command, please?', asked the waiter.") << endl;
 
+#if __cpp_lib_format <= 202106L
   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)),
+                  n)
+#endif
        << endl;
 
+#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")
+#endif
        << endl;
 }
 EOF