> 2026-02-03 Bruno Haible <[email protected]>
>
> isnan: Make more C++ safe.
> * lib/math.in.h (isnan): In C++ mode, define as a template with three
> instantiations, instead of as a macro.
This patch produced a compilation error in C++ mode on CentOS 7 and NetBSD 10:
In file included from ../gllib/math.h:46,
from ../../gltests/test-math-h-c++.cc:22:
../gllib/math.h:3213:27: error: expected unqualified-id before ‘sizeof’
3213 | template <typename T> int isnan (T);
| ^~~~~
../gllib/math.h:3213:27: error: expected ‘)’ before ‘sizeof’
Fixed as follows.
2026-02-09 Bruno Haible <[email protected]>
isnan: Fix compilation error in C++ mode on NetBSD (regr. 2026-02-03).
* lib/math.in.h (isnan): Undefine before defining as a template.
diff --git a/lib/math.in.h b/lib/math.in.h
index 3b33ab4a9e..4174445d38 100644
--- a/lib/math.in.h
+++ b/lib/math.in.h
@@ -2650,6 +2650,7 @@ _GL_EXTERN_C int rpl_isnanl (long double x)
_GL_ATTRIBUTE_CONST;
# define gl_isnan_l(x) rpl_isnanl (x)
# endif
# ifdef __cplusplus
+# undef isnan
template <typename T> int isnan (T);
template <> inline int isnan<float> (float x) { return gl_isnan_f (x); }
template <> inline int isnan<double> (double x) { return gl_isnan_d (x); }
@@ -2663,6 +2664,7 @@ template <> inline int isnan<long double> (long double x)
{ return gl_isnan_l (x
# endif
# elif (__GNUC__ >= 4) || (__clang_major__ >= 4)
# ifdef __cplusplus
+# undef isnan
template <typename T> int isnan (T);
template <> inline int isnan<float> (float x) { return __builtin_isnan (x); }
template <> inline int isnan<double> (double x) { return __builtin_isnan (x); }