# Try to find compiler option for ISO C++ 20 support.
cat <<\EOF > conftest.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 conftest.cc 2>/dev/null; then
:
elif ${CXX} ${CXXFLAGS} -std=gnu++20 ${CPPFLAGS} -c conftest.cc 2>/dev/null; then
CXXFLAGS="${CXXFLAGS} -std=gnu++20"
+elif ${CXX} ${CXXFLAGS} -std=gnu++26 ${CPPFLAGS} -c conftest.cc 2>/dev/null; then
+ CXXFLAGS="${CXXFLAGS} -std=gnu++26"
fi
AM_GNU_GETTEXT([external])
// Source code of the ISO C++ 20 program.
+// Note: The API has changed three years after ISO C++ 20. Code that was working
+// fine with g++ 13.1, 13.2 and clang++ 17, 18 (with option -std=gnu++20)
+// no longer compiles with g++ 13.3 or newer and clang++ 19 or newer. Thus the
+// need to test __cpp_lib_format, whose value is 202106L for the older compilers
+// and 202110L for the newer compilers. See
+// <https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2023/p2905r2.html>.
+// The replacement API, presented in
+// <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
+// option -std=gnu++26.
#include <format>
#include <iostream>
bindtextdomain ("hello-c++20", LOCALEDIR);
cout << _("Hello, world!") << endl;
+#if __cpp_lib_format <= 202106L
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}.")),
+ getpid ())
+#endif
<< endl;
}