[PATCH] math.h: Do use __MATH_TG_BUILTIN_CLASSIFY for C++

Adhemerval Zanella adhemerval.zanella@linaro.org
Mon Dec 29 15:12:00 GMT 2025


The __MATH_TG_BUILTIN_CLASSIFY macro can not be used in C++ mode due
it might use __builtin_types_compatible_p, which is a C-only builtin.

Checked with bmg targetting x86_64-linux-gnu and on x86_64-linux-gnu
and aarch64 with gcc-15 and clang-18.
---
 math/math.h | 43 ++++++++++++++++++++++++++-----------------
 1 file changed, 26 insertions(+), 17 deletions(-)

diff --git a/math/math.h b/math/math.h
index 96b64379f7..49489293fc 100644
--- a/math/math.h
+++ b/math/math.h
@@ -1173,21 +1173,25 @@ enum
 
 /* Return number of classification appropriate for X.  */
 # if ((__GNUC_PREREQ (4,4) && !defined __SUPPORT_SNAN__)		      \
-      || __glibc_clang_prereq (2,8))					      \
-     && (!defined __OPTIMIZE_SIZE__ || defined __cplusplus)
-     /* The check for __cplusplus allows the use of the builtin, even
-	when optimization for size is on.  This is provided for
-	libstdc++, only to let its configure test work when it is built
-	with -Os.  No further use of this definition of fpclassify is
-	expected in C++ mode, since libstdc++ provides its own version
-	of fpclassify in cmath (which undefines fpclassify).  */
-#  define fpclassify(x)							      \
-  __MATH_TG_BUILTIN_CLASSIFY ((x),					      \
-			      __builtin_fpclassify, (FP_NAN, FP_INFINITE,     \
-						     FP_NORMAL, FP_SUBNORMAL, \
-						     FP_ZERO, x),	      \
-			      fpclassify, (x),				      \
-			      __FP_BUILTIN_FPCLASSIFY_DENORMAL)
+       || __glibc_clang_prereq (2,8))					      \
+     && !defined __cplusplus
+  /* The __MATH_TG_BUILTIN_CLASSIFY macro can not be used in C++ mode due
+     it might use __builtin_types_compatible_p, which is C-only builtin.  */
+#  define fpclassify(x)                                                       \
+  __MATH_TG_BUILTIN_CLASSIFY ((x),                                            \
+                              __builtin_fpclassify, (FP_NAN, FP_INFINITE,     \
+                                                     FP_NORMAL, FP_SUBNORMAL, \
+                                                     FP_ZERO, x),             \
+                              fpclassify, (x),                                \
+                              __FP_BUILTIN_FPCLASSIFY_DENORMAL)
+# elif defined __cplusplus
+   /* The check for __cplusplus allows the use of the builtin, even
+      when optimization for size is on.  This is provided for
+      libstdc++ and no further use of this definition of fpclassify is
+      expected in C++ mode, since libstdc++ provides its own version
+      of fpclassify in cmath (which undefines fpclassify).  */
+#  define fpclassify(x) __builtin_fpclassify (FP_NAN, FP_INFINITE,	      \
+     FP_NORMAL, FP_SUBNORMAL, FP_ZERO, x)
 # else
 #  define fpclassify(x) __MATH_TG ((x), __fpclassify, (x))
 # endif
@@ -1247,12 +1251,17 @@ enum
 #  define isinf(x) \
     (__builtin_types_compatible_p (__typeof (x), _Float128) \
      ? __isinff128 (x) : __builtin_isinf_sign (x))
-# elif (__GNUC_PREREQ (4,4) && !defined __SUPPORT_SNAN__) \
-       || __glibc_clang_prereq (3,7)
+  /* The __MATH_TG_BUILTIN_CLASSIFY macro can not be used in C++ mode due
+     it might use __builtin_types_compatible_p, which is C-only builtin.  */
+# elif ((__GNUC_PREREQ (4,4) && !defined __SUPPORT_SNAN__) \
+        || __glibc_clang_prereq (3,7)) \
+     && !defined __cplusplus
 #  define isinf(x) __MATH_TG_BUILTIN_CLASSIFY ((x),			      \
 					       __builtin_isinf_sign, (x),     \
 					       isinf, (x),		      \
 					       __FP_BUILTIN_ISINF_SIGN_DENORMAL)
+# elif defined __cplusplus
+#  define isinf(x) __builtin_isinf_sign (x)
 # else
 #  define isinf(x) __MATH_TG ((x), __isinf, (x))
 # endif
-- 
2.43.0



More information about the Libc-alpha mailing list