bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

isnanf, isnand: Fix conflict with Solaris <ieeefp.h>


From: Bruno Haible
Subject: isnanf, isnand: Fix conflict with Solaris <ieeefp.h>
Date: Fri, 13 Oct 2023 12:14:49 +0200

On Solaris 10 and 11, I see a compilation error:

In file included from ../../gltests/snan.h:22:0,
                 from ../../gltests/test-snan-2.c:22:
/usr/include/ieeefp.h:159:12: error: expected declaration specifiers or ‘...’ 
before ‘(’ token
 extern int isnanf(float);
            ^
/usr/include/ieeefp.h:160:12: error: expected declaration specifiers or ‘...’ 
before ‘(’ token
 extern int isnand(double);
            ^
gmake[4]: *** [Makefile:5571: test-snan-2.o] Error 1

The cause is a conflict between the declaration if isnanf and isnand as
functions, in <ieeefp.h>, and their definition as macros in gnulib's math.h.
This patch fixes it.


2023-10-13  Bruno Haible  <bruno@clisp.org>

        isnanf, isnand: Fix conflict with Solaris <ieeefp.h>.
        * lib/math.in.h (isnanf, isnand): On Solaris and IRIX, declare this
        function, instead of defining it as a macro.

diff --git a/lib/math.in.h b/lib/math.in.h
index b18627ae0a..202f843fc4 100644
--- a/lib/math.in.h
+++ b/lib/math.in.h
@@ -2545,16 +2545,22 @@ _GL_WARN_REAL_FLOATING_DECL (isinf);
 #if @GNULIB_ISNANF@
 /* Test for NaN for 'float' numbers.  */
 # if @HAVE_ISNANF@
+#  if defined __sun || defined __sgi
+/* Solaris and IRIX have isnanf() and declare it in <ieeefp.h>.  We cannot
+   define isnanf as a macro, because that would conflict with <ieeefp.h>.  */
+_GL_EXTERN_C int isnanf (float x);
+#  else
 /* The original <math.h> included above provides a declaration of isnan macro
    or (older) isnanf function.  */
-#  if (__GNUC__ >= 4) || (__clang_major__ >= 4)
+#   if (__GNUC__ >= 4) || (__clang_major__ >= 4)
     /* GCC >= 4.0 and clang provide a type-generic built-in for isnan.
        GCC >= 4.0 also provides __builtin_isnanf, but clang doesn't.  */
-#   undef isnanf
-#   define isnanf(x) __builtin_isnan ((float)(x))
-#  elif defined isnan
-#   undef isnanf
-#   define isnanf(x) isnan ((float)(x))
+#    undef isnanf
+#    define isnanf(x) __builtin_isnan ((float)(x))
+#   elif defined isnan
+#    undef isnanf
+#    define isnanf(x) isnan ((float)(x))
+#   endif
 #  endif
 # else
 /* Test whether X is a NaN.  */
@@ -2569,15 +2575,21 @@ _GL_EXTERN_C int isnanf (float x);
    This function is a gnulib extension, unlike isnan() which applied only
    to 'double' numbers earlier but now is a type-generic macro.  */
 # if @HAVE_ISNAND@
+#  if defined __sun || defined __sgi
+/* Solaris and IRIX have isnand() and declare it in <ieeefp.h>.  We cannot
+   define isnand as a macro, because that would conflict with <ieeefp.h>.  */
+_GL_EXTERN_C int isnand (double x);
+#  else
 /* The original <math.h> included above provides a declaration of isnan
    macro.  */
-#  if (__GNUC__ >= 4) || (__clang_major__ >= 4)
+#   if (__GNUC__ >= 4) || (__clang_major__ >= 4)
     /* GCC >= 4.0 and clang provide a type-generic built-in for isnan.  */
-#   undef isnand
-#   define isnand(x) __builtin_isnan ((double)(x))
-#  else
-#   undef isnand
-#   define isnand(x) isnan ((double)(x))
+#    undef isnand
+#    define isnand(x) __builtin_isnan ((double)(x))
+#   else
+#    undef isnand
+#    define isnand(x) isnan ((double)(x))
+#   endif
 #  endif
 # else
 /* Test whether X is a NaN.  */






reply via email to

[Prev in Thread] Current Thread [Next in Thread]