Skip to content

Commit bbcf24a

Browse files
committed
[libcxx] Undefine all supported C math functions
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.
1 parent b477d1d commit bbcf24a

File tree

2 files changed

+74
-65
lines changed

2 files changed

+74
-65
lines changed

libcxx/include/math.h

Lines changed: 68 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -307,53 +307,74 @@ long double truncl(long double x);
307307
// back to C++ linkage before including these C++ headers.
308308
extern "C++" {
309309

310-
# ifdef fpclassify
311-
# undef fpclassify
312-
# endif
313-
314-
# ifdef signbit
315-
# undef signbit
316-
# endif
317-
318-
# ifdef isfinite
319-
# undef isfinite
320-
# endif
321-
322-
# ifdef isinf
323-
# undef isinf
324-
# endif
325-
326-
# ifdef isnan
327-
# undef isnan
328-
# endif
329-
330-
# ifdef isnormal
331-
# undef isnormal
332-
# endif
333-
334-
# ifdef isgreater
335-
# undef isgreater
336-
# endif
337-
338-
# ifdef isgreaterequal
339-
# undef isgreaterequal
340-
# endif
341-
342-
# ifdef isless
343-
# undef isless
344-
# endif
345-
346-
# ifdef islessequal
347-
# undef islessequal
348-
# endif
349-
350-
# ifdef islessgreater
351-
# undef islessgreater
352-
# endif
353-
354-
# ifdef isunordered
355-
# undef isunordered
356-
# endif
310+
# undef acos
311+
# undef acosh
312+
# undef asin
313+
# undef asinh
314+
# undef atan
315+
# undef atan2
316+
# undef atanh
317+
# undef cbrt
318+
# undef ceil
319+
# undef copysign
320+
# undef cos
321+
# undef cosh
322+
# undef erf
323+
# undef erfc
324+
# undef exp
325+
# undef exp2
326+
# undef expm1
327+
# undef fabs
328+
# undef fdim
329+
# undef floor
330+
# undef fma
331+
# undef fmax
332+
# undef fmin
333+
# undef fmod
334+
# undef fpclassify
335+
# undef frexp
336+
# undef hypot
337+
# undef ilogb
338+
# undef isfinite
339+
# undef isgreater
340+
# undef isgreaterequal
341+
# undef isinf
342+
# undef isless
343+
# undef islessequal
344+
# undef islessgreater
345+
# undef isnan
346+
# undef isnormal
347+
# undef isunordered
348+
# undef ldexp
349+
# undef lgamma
350+
# undef llrint
351+
# undef llround
352+
# undef log
353+
# undef log10
354+
# undef log1p
355+
# undef log2
356+
# undef logb
357+
# undef lrint
358+
# undef lround
359+
# undef modf
360+
# undef nearbyint
361+
# undef nextafter
362+
# undef nexttoward
363+
# undef pow
364+
# undef remainder
365+
# undef remquo
366+
# undef rint
367+
# undef round
368+
# undef scalbln
369+
# undef scalbn
370+
# undef signbit
371+
# undef sin
372+
# undef sinh
373+
# undef sqrt
374+
# undef tan
375+
# undef tanh
376+
# undef tgamma
377+
# undef trunc
357378

358379
# include <__math/abs.h>
359380
# include <__math/copysign.h>

libcxx/include/stdlib.h

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -98,15 +98,9 @@ void *aligned_alloc(size_t alignment, size_t size); // C11
9898
extern "C++" {
9999
// abs
100100

101-
# ifdef abs
102-
# undef abs
103-
# endif
104-
# ifdef labs
105-
# undef labs
106-
# endif
107-
# ifdef llabs
108-
# undef llabs
109-
# endif
101+
# undef abs
102+
# undef labs
103+
# undef llabs
110104

111105
// MSVCRT already has the correct prototype in <stdlib.h> if __cplusplus is defined
112106
# if !defined(_LIBCPP_MSVCRT)
@@ -128,15 +122,9 @@ _LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI long double abs(long double __lcp
128122

129123
// div
130124

131-
# ifdef div
132-
# undef div
133-
# endif
134-
# ifdef ldiv
135-
# undef ldiv
136-
# endif
137-
# ifdef lldiv
138-
# undef lldiv
139-
# endif
125+
# undef div
126+
# undef ldiv
127+
# undef lldiv
140128

141129
// MSVCRT already has the correct prototype in <stdlib.h> if __cplusplus is defined
142130
# if !defined(_LIBCPP_MSVCRT)

0 commit comments

Comments
 (0)