groff
[Top][All Lists]
Advanced

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

Re: signbit(), C++, and Solaris 10


From: Bruno Haible
Subject: Re: signbit(), C++, and Solaris 10
Date: Fri, 06 Dec 2024 20:56:15 +0100

G. Branden Robinson wrote:
> > Therefore: please point me to a tarball that exhibits the problem for
> > you, so that I can reproduce.
> 
> https://paste.c-net.org/HairedMaciver

Thanks; with this download (groff-1.23.0.2599-3cde9.tar.gz) I could
reproduce the issue.

As usual, the first step is to get an overview of the problem. In this case,
it means to look at all occurrences of 'signbit' in the compilation unit.
That is, run

  $ gmake V=1

in order to get the failing command

  g++ -m64 -std=gnu++11 -DHAVE_CONFIG_H -I. -I.. -I./src/include  
-I../src/include -I../lib -I./src/include -I./lib 
-I/home/haible/prefix-x86_64/include -Wall -D_REENTRANT  -g -O2 -MT 
src/devices/grodvi/dvi.o -MD -MP -MF $depbase.Tpo -c -o 
src/devices/grodvi/dvi.o ../src/devices/grodvi/dvi.cpp

then use the preprocessor:

  $ g++ -m64 -std=gnu++11 -DHAVE_CONFIG_H -I. -I.. -I./src/include  
-I../src/include -I../lib -I./src/include -I./lib 
-I/home/haible/prefix-x86_64/include -Wall -D_REENTRANT  -g -O2 -E -dD 
../src/devices/grodvi/dvi.cpp > i
  $ grep signbit i

The output

-------------------------------------------------------------------------------
#undef signbit
#define signbit(x) ( sizeof (x) == sizeof (float) ? __builtin_signbitf(x) : 
sizeof (x) == sizeof (double) ? __builtin_signbit(x) : __builtin_signbitl(x))
#undef signbit
 inline bool signbit(float __X) { return __builtin_signbitf(__X); }
 inline bool signbit(double __X) { return __builtin_signbit(__X); }
 inline bool signbit(long double __X) { return __builtin_signbitl(__X); }
  signbit(_Tp __X) { return __X < 0 ? true : false; }
using std::signbit;
#undef signbit
extern "C" int gl_signbitf (float arg);
extern "C" int gl_signbitd (double arg);
extern "C" int gl_signbitl (long double arg);
#define gl_signbitf_OPTIMIZED_MACRO 
#define gl_signbitf(arg) __extension__ ({ union { float _value; unsigned int 
_word[_GL_NUM_UINT_WORDS (float)]; } _m; _m._value = (arg); 
(_m._word[FLT_SIGNBIT_WORD] >> FLT_SIGNBIT_BIT) & 1; })
#define gl_signbitd_OPTIMIZED_MACRO 
#define gl_signbitd(arg) __extension__ ({ union { double _value; unsigned int 
_word[_GL_NUM_UINT_WORDS (double)]; } _m; _m._value = (arg); 
(_m._word[DBL_SIGNBIT_WORD] >> DBL_SIGNBIT_BIT) & 1; })
#define gl_signbitl_OPTIMIZED_MACRO 
#define gl_signbitl(arg) __extension__ ({ union { long double _value; unsigned 
int _word[_GL_NUM_UINT_WORDS (long double)]; } _m; _m._value = (arg); 
(_m._word[LDBL_SIGNBIT_WORD] >> LDBL_SIGNBIT_BIT) & 1; })
#define signbit(x) (sizeof (x) == sizeof (long double) ? gl_signbitl (x) : 
sizeof (x) == sizeof (double) ? gl_signbitd (x) : gl_signbitf (x))
#define GNULIB_defined_signbit 1
static inline int _gl_cxx_signbitf (float f) { return (sizeof (f) == sizeof 
(long double) ? __extension__ ({ union { long double _value; unsigned int 
_word[((sizeof (long double) + sizeof (unsigned int) - 1) / sizeof (unsigned 
int))]; } _m; _m._value = (f); (_m._word[
) & 1; })); } static inline int _gl_cxx_signbitd (double d) { return (sizeof 
(d) == sizeof (long double) ? __extension__ ({ union { long double _value; 
unsigned int _word[((sizeof (long double) + sizeof (unsigned int) - 1) / sizeof 
(unsigned int))]; } _m; _m._value = (d); (_m._word[
) & 1; })); } static inline int _gl_cxx_signbitl (long double l) { return 
(sizeof (l) == sizeof (long double) ? __extension__ ({ union { long double 
_value; unsigned int _word[((sizeof (long double) + sizeof (unsigned int) - 1) 
/ sizeof (unsigned int))]; } _m; _m._value = (l); (_m._word[
#undef signbit
 inline bool signbit (float f) { return _gl_cxx_signbitf (f); } inline bool 
signbit (double d) { return _gl_cxx_signbitd (d); } inline bool signbit (long 
double l) { return _gl_cxx_signbitl (l); }
-------------------------------------------------------------------------------

shows the inline function definitions from /usr/include/iso/math_c99.h.
Such inline function definitions can only be overridden through a #define,
in this case
  #define signbit rpl_signbit

A look in /usr/include/iso/math_c99.h also shows the condition of
existence of these inline function definitions: In C++ 11 or newer. This is
consistent with
  <https://en.cppreference.com/w/cpp/numeric/math/signbit>

The gnulib fix is thus quite obvious at this point:


2024-12-06  Bruno Haible  <bruno@clisp.org>

        signbit: Fix compilation error with g++ 5.5 on Solaris 10.
        Reported by G. Branden Robinson <g.branden.robinson@gmail.com> in
        <https://lists.gnu.org/archive/html/bug-gnulib/2024-11/msg00180.html>.
        * lib/math.in.h (signbit): In C++ 11 or newer, assume that <math.h> or
        <cmath> may define signbit through three inline functions.

diff --git a/lib/math.in.h b/lib/math.in.h
index 75d6351a9c..8f687b28f9 100644
--- a/lib/math.in.h
+++ b/lib/math.in.h
@@ -2818,7 +2818,7 @@ _GL_EXTERN_C int gl_signbitl (long double arg);
 #  if defined signbit || defined GNULIB_NAMESPACE
 _GL_MATH_CXX_REAL_FLOATING_DECL_1 (signbit)
 #   undef signbit
-#   if __GNUC__ >= 6 || (defined __clang__ && !((defined __APPLE__ && defined 
__MACH__) || defined __FreeBSD__ || defined __OpenBSD__ || defined _AIX || 
(defined _WIN32 && !defined __CYGWIN__)))
+#   if __cplusplus >= 201103L || __GNUC__ >= 6 || (defined __clang__ && 
!((defined __APPLE__ && defined __MACH__) || defined __FreeBSD__ || defined 
__OpenBSD__ || defined _AIX || (defined _WIN32 && !defined __CYGWIN__)))
   /* This platform's <cmath> possibly defines signbit through a set of inline
      functions.  */
 _GL_MATH_CXX_REAL_FLOATING_DECL_2 (signbit, rpl_signbit, bool)






reply via email to

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