Building groff-1.24.0.rc2 on FreeBSD 15, I get this compilation error:

  CXX      src/roff/troff/env.o
In file included from ../src/roff/troff/env.cpp:28:
In file included from /usr/include/c++/v1/vector:325:
In file included from /usr/include/c++/v1/__format/formatter_bool.h:16:
In file included from /usr/include/c++/v1/__format/concepts.h:16:
In file included from /usr/include/c++/v1/__format/format_parse_context.h:16:
In file included from /usr/include/c++/v1/string_view:251:
In file included from /usr/include/c++/v1/compare:174:
In file included from /usr/include/c++/v1/cmath:327:
/usr/include/c++/v1/__math/special_functions.h:51:16: error: expected 
unqualified-id
   51 |   if (!__math::isfinite(__H_n)) {
      |                ^
./lib/math.h:3018:4: note: expanded from macro 'isfinite'
 3018 |    (sizeof (x) == sizeof (long double) ? gl_isfinitel (x) : \
      |    ^

It was supposed to be fixed by the 2025-12-19 patch
"isfinite-no-c++: New module.". But gnulib's <math.h> is still overriding
isfinite with a macro.

This patch fixes it.


2026-01-27  Bruno Haible  <[email protected]>

        isfinite-no-c++: Make more C++ safe.
        * lib/math.in.h (isfinite): In C++ mode, define as a template with three
        instantiations, instead of as a macro.

diff --git a/lib/math.in.h b/lib/math.in.h
index 680e1c5347..210ac99cf3 100644
--- a/lib/math.in.h
+++ b/lib/math.in.h
@@ -2466,11 +2466,18 @@ _GL_CXXALIASWARN (yn);
 _GL_EXTERN_C int gl_isfinitef (float x);
 _GL_EXTERN_C int gl_isfinited (double x);
 _GL_EXTERN_C int gl_isfinitel (long double x);
-#  undef isfinite
-#  define isfinite(x) \
-   (sizeof (x) == sizeof (long double) ? gl_isfinitel (x) : \
-    sizeof (x) == sizeof (double) ? gl_isfinited (x) : \
-    gl_isfinitef (x))
+#  ifdef __cplusplus
+template <typename T> int isfinite (T);
+template <> inline int isfinite<float> (float x) { return gl_isfinitef (x); }
+template <> inline int isfinite<double> (double x) { return gl_isfinited (x); }
+template <> inline int isfinite<long double> (long double x) { return 
gl_isfinitel (x); }
+#  else
+#   undef isfinite
+#   define isfinite(x) \
+      (sizeof (x) == sizeof (long double) ? gl_isfinitel (x) : \
+       sizeof (x) == sizeof (double) ? gl_isfinited (x) : \
+       gl_isfinitef (x))
+#  endif
 # endif
 # if @GNULIB_ISFINITE@ && defined __cplusplus
 #  if defined isfinite || defined GNULIB_NAMESPACE




Reply via email to