[libcxx-commits] [libcxx] [libcxx] Undefine all supported C math functions (PR #94533)
via libcxx-commits
libcxx-commits at lists.llvm.org
Wed Jun 5 13:32:53 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-libcxx
Author: Petr Hosek (petrhosek)
<details>
<summary>Changes</summary>
The C standard allows these to be defined as macros which is problem when providing the C++ versions and so we need to undefine the C macros first. Rather than undefining these selectively, we should undefine all of them since we have any guarantees which are going to be defined as macros and it depeneds on the target platform.
We don't need to guard these with #ifdef since undefining a symbol that's not defined is not an error.
This is related to issue #<!-- -->84879.
---
Full diff: https://github.com/llvm/llvm-project/pull/94533.diff
2 Files Affected:
- (modified) libcxx/include/math.h (+68-47)
- (modified) libcxx/include/stdlib.h (+6-18)
``````````diff
diff --git a/libcxx/include/math.h b/libcxx/include/math.h
index 4e6304a753984..893dca8dc1c17 100644
--- a/libcxx/include/math.h
+++ b/libcxx/include/math.h
@@ -307,53 +307,74 @@ long double truncl(long double x);
// back to C++ linkage before including these C++ headers.
extern "C++" {
-# ifdef fpclassify
-# undef fpclassify
-# endif
-
-# ifdef signbit
-# undef signbit
-# endif
-
-# ifdef isfinite
-# undef isfinite
-# endif
-
-# ifdef isinf
-# undef isinf
-# endif
-
-# ifdef isnan
-# undef isnan
-# endif
-
-# ifdef isnormal
-# undef isnormal
-# endif
-
-# ifdef isgreater
-# undef isgreater
-# endif
-
-# ifdef isgreaterequal
-# undef isgreaterequal
-# endif
-
-# ifdef isless
-# undef isless
-# endif
-
-# ifdef islessequal
-# undef islessequal
-# endif
-
-# ifdef islessgreater
-# undef islessgreater
-# endif
-
-# ifdef isunordered
-# undef isunordered
-# endif
+# undef acos
+# undef acosh
+# undef asin
+# undef asinh
+# undef atan
+# undef atan2
+# undef atanh
+# undef cbrt
+# undef ceil
+# undef copysign
+# undef cos
+# undef cosh
+# undef erf
+# undef erfc
+# undef exp
+# undef exp2
+# undef expm1
+# undef fabs
+# undef fdim
+# undef floor
+# undef fma
+# undef fmax
+# undef fmin
+# undef fmod
+# undef fpclassify
+# undef frexp
+# undef hypot
+# undef ilogb
+# undef isfinite
+# undef isgreater
+# undef isgreaterequal
+# undef isinf
+# undef isless
+# undef islessequal
+# undef islessgreater
+# undef isnan
+# undef isnormal
+# undef isunordered
+# undef ldexp
+# undef lgamma
+# undef llrint
+# undef llround
+# undef log
+# undef log10
+# undef log1p
+# undef log2
+# undef logb
+# undef lrint
+# undef lround
+# undef modf
+# undef nearbyint
+# undef nextafter
+# undef nexttoward
+# undef pow
+# undef remainder
+# undef remquo
+# undef rint
+# undef round
+# undef scalbln
+# undef scalbn
+# undef signbit
+# undef sin
+# undef sinh
+# undef sqrt
+# undef tan
+# undef tanh
+# undef tgamma
+# undef trunc
# include <__math/abs.h>
# include <__math/copysign.h>
diff --git a/libcxx/include/stdlib.h b/libcxx/include/stdlib.h
index a74344d49150c..b1151b58a356f 100644
--- a/libcxx/include/stdlib.h
+++ b/libcxx/include/stdlib.h
@@ -98,15 +98,9 @@ void *aligned_alloc(size_t alignment, size_t size); // C11
extern "C++" {
// abs
-# ifdef abs
-# undef abs
-# endif
-# ifdef labs
-# undef labs
-# endif
-# ifdef llabs
-# undef llabs
-# endif
+# undef abs
+# undef labs
+# undef llabs
// MSVCRT already has the correct prototype in <stdlib.h> if __cplusplus is defined
# if !defined(_LIBCPP_MSVCRT)
@@ -128,15 +122,9 @@ _LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI long double abs(long double __lcp
// div
-# ifdef div
-# undef div
-# endif
-# ifdef ldiv
-# undef ldiv
-# endif
-# ifdef lldiv
-# undef lldiv
-# endif
+# undef div
+# undef ldiv
+# undef lldiv
// MSVCRT already has the correct prototype in <stdlib.h> if __cplusplus is defined
# if !defined(_LIBCPP_MSVCRT)
``````````
</details>
https://github.com/llvm/llvm-project/pull/94533
More information about the libcxx-commits
mailing list