> 2026-02-03  Bruno Haible  <[email protected]>
> 
>       signbit: Make more C++ safe.
>       * lib/math.in.h (signbit): In C++ mode, define as a template with three
>       instantiations, instead of as a macro.

This patch produces a compilation error on macOS 14:

In file included from ../../gltests/test-assert-h-c++.cc:26:
In file included from 
/Applications/Xcode_15.4.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/iostream:43:
In file included from 
/Applications/Xcode_15.4.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/ios:222:
In file included from 
/Applications/Xcode_15.4.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/__locale:21:
In file included from 
/Applications/Xcode_15.4.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/mutex:192:
In file included from 
/Applications/Xcode_15.4.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/__condition_variable/condition_variable.h:16:
In file included from 
/Applications/Xcode_15.4.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/__mutex/mutex.h:13:
In file included from 
/Applications/Xcode_15.4.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/__threading_support:39:
../gllib/math.h:3333:36: error: call to 'signbit' is ambiguous
_GL_MATH_CXX_REAL_FLOATING_DECL_1 (signbit)
                                   ^~~~~~~
../gllib/math.h:638:10: note: expanded from macro 
'_GL_MATH_CXX_REAL_FLOATING_DECL_1'
  return func (f);                                                  \
         ^~~~
/Applications/Xcode_15.4.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/math.h:370:57:
 note: candidate function [with _A1 = float, $1 = 0]
_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI bool signbit(_A1 __x) 
_NOEXCEPT {
                                                        ^
../gllib/math.h:3266:24: note: candidate function [with T = float]
template <> inline int signbit<float> (float x) { return __builtin_signbitf 
(x); }
                       ^
../gllib/math.h:3333:36: error: call to 'signbit' is ambiguous
_GL_MATH_CXX_REAL_FLOATING_DECL_1 (signbit)
                                   ^~~~~~~
../gllib/math.h:643:10: note: expanded from macro 
'_GL_MATH_CXX_REAL_FLOATING_DECL_1'
  return func (d);                                                  \
         ^~~~
/Applications/Xcode_15.4.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/math.h:370:57:
 note: candidate function [with _A1 = double, $1 = 0]
_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI bool signbit(_A1 __x) 
_NOEXCEPT {
                                                        ^
../gllib/math.h:3267:24: note: candidate function [with T = double]
template <> inline int signbit<double> (double x) { return __builtin_signbit 
(x); }
                       ^
../gllib/math.h:3333:36: error: call to 'signbit' is ambiguous
_GL_MATH_CXX_REAL_FLOATING_DECL_1 (signbit)
                                   ^~~~~~~
../gllib/math.h:648:10: note: expanded from macro 
'_GL_MATH_CXX_REAL_FLOATING_DECL_1'
  return func (l);                                                  \
         ^~~~
/Applications/Xcode_15.4.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/math.h:370:57:
 note: candidate function [with _A1 = long double, $1 = 0]
_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI bool signbit(_A1 __x) 
_NOEXCEPT {
                                                        ^
../gllib/math.h:3268:24: note: candidate function [with T = long double]
template <> inline int signbit<long double> (long double x) { return 
__builtin_signbitl (x); }
                       ^
In file included from ../../gltests/test-assert-h-c++.cc:26:
In file included from 
/Applications/Xcode_15.4.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/iostream:43:
In file included from 
/Applications/Xcode_15.4.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/ios:222:
In file included from 
/Applications/Xcode_15.4.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/__locale:21:
In file included from 
/Applications/Xcode_15.4.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/mutex:192:
In file included from 
/Applications/Xcode_15.4.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/__condition_variable/condition_variable.h:16:
In file included from 
/Applications/Xcode_15.4.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/__mutex/mutex.h:13:
/Applications/Xcode_15.4.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/__threading_support:407:11:
 warning: The symbol ::nanosleep refers to the system function. Use 
gnulib::nanosleep instead. [-Wuser-defined-warnings]
   while (nanosleep(&__ts, &__ts) == -1 && errno == EINTR);
          ^
../gllib/time.h:788:1: note: from 'diagnose_if' attribute on 'nanosleep':
_GL_CXXALIASWARN (nanosleep);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~
../gllib/time.h:385:4: note: expanded from macro '_GL_CXXALIASWARN'
   _GL_CXXALIASWARN_1 (func, GNULIB_NAMESPACE)
   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../gllib/time.h:387:4: note: expanded from macro '_GL_CXXALIASWARN_1'
   _GL_CXXALIASWARN_2 (func, namespace)
   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../gllib/time.h:392:5: note: expanded from macro '_GL_CXXALIASWARN_2'
    _GL_WARN_ON_USE (func, \
    ^~~~~~~~~~~~~~~~~~~~~~~~
../gllib/time.h:560:19: note: expanded from macro '_GL_WARN_ON_USE'
  __attribute__ ((__diagnose_if__ (1, message, "warning")))
                  ^                ~
1 warning and 3 errors generated.
make[4]: *** [test-assert-h-c++.o] Error 1


I hope the following patch will fix it.


2026-02-09  Bruno Haible  <[email protected]>

        signbit: Fix compil. error in C++ mode on macOS 14 (regr. 2026-02-03).
        * lib/math.in.h (signbit): Don't define as a template if the compiler
        is clang.

diff --git a/lib/math.in.h b/lib/math.in.h
index 4174445d38..14218ea08c 100644
--- a/lib/math.in.h
+++ b/lib/math.in.h
@@ -2716,7 +2716,7 @@ _GL_WARN_REAL_FLOATING_DECL (isnan);
       && (!defined __cplusplus || __cplusplus < 201103))
 #  undef signbit
    /* GCC >= 4.0 and clang provide three built-ins for signbit.  */
-#  ifdef __cplusplus
+#  if defined __cplusplus && !defined __clang__
 template <typename T> int signbit (T);
 template <> inline int signbit<float> (float x) { return __builtin_signbitf 
(x); }
 template <> inline int signbit<double> (double x) { return __builtin_signbit 
(x); }
@@ -2770,7 +2770,7 @@ _GL_EXTERN_C int gl_signbitl (long double arg);
         })
 #   endif
 #  endif
-#  ifdef __cplusplus
+#  if defined __cplusplus && !defined __clang__
 template <typename T> int signbit (T);
 template <> inline int signbit<float> (float x) { return gl_signbitf (x); }
 template <> inline int signbit<double> (double x) { return gl_signbitd (x); }




Reply via email to