diff --git a/libcxx/include/math.h b/libcxx/include/math.h index 4e6304a753984..2695be9a497bc 100644 --- a/libcxx/include/math.h +++ b/libcxx/include/math.h @@ -307,53 +307,79 @@ 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 +// According to section 7.1.4 Use of library functions of the C standard, any +// function declared in a header may be additionally implemented as a +// function-like macro defined in the header, so if a library function is +// declared explicitly when the C standard library header is included, as is +// the case here, we need to use #undef to remove any macro definition. +# 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 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 if __cplusplus is defined # if !defined(_LIBCPP_MSVCRT)