[libcxx-commits] [PATCH] D60097: Fix implementation of ::abs and std::abs LWG 2192.

Eric Fiselier via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Sun Aug 4 14:02:02 PDT 2019


EricWF marked an inline comment as done.
EricWF added inline comments.


================
Comment at: libcxx/trunk/include/stdlib.h:100
 #ifdef __cplusplus
-
-extern "C++" {
-
-#undef abs
-#undef div
-#undef labs
-#undef ldiv
-#ifndef _LIBCPP_HAS_NO_LONG_LONG
-#undef llabs
-#undef lldiv
-#endif
-
-// MSVCRT already has the correct prototype in <stdlib.h> if __cplusplus is defined
-#if !defined(_LIBCPP_MSVCRT) && !defined(__sun__) && !defined(_AIX)
-inline _LIBCPP_INLINE_VISIBILITY long      abs(     long __x) _NOEXCEPT {return  labs(__x);}
-#ifndef _LIBCPP_HAS_NO_LONG_LONG
-inline _LIBCPP_INLINE_VISIBILITY long long abs(long long __x) _NOEXCEPT {return llabs(__x);}
-#endif // _LIBCPP_HAS_NO_LONG_LONG
-
-inline _LIBCPP_INLINE_VISIBILITY  ldiv_t div(     long __x,      long __y) _NOEXCEPT {return  ldiv(__x, __y);}
-#ifndef _LIBCPP_HAS_NO_LONG_LONG
-inline _LIBCPP_INLINE_VISIBILITY lldiv_t div(long long __x, long long __y) _NOEXCEPT {return lldiv(__x, __y);}
-#endif // _LIBCPP_HAS_NO_LONG_LONG
-#endif // _LIBCPP_MSVCRT / __sun__ / _AIX
-
-}  // extern "C++"
-
+#include <math.h>
 #endif  // __cplusplus
----------------
raj.khem wrote:
> Should this be `#include_next <math.h>` here ?  this changes causes failures when an app defines a math.h in its own sources and adds -I path to that location, any source code then having  `include <stdlib.h>` ends up including apps math.h via system provided `stdlib.h` you can see this happening with gnu groff utility 
If I'm not mistaken, it's undefined behavior to define your own `math.h` and add it to the `<...>` include path.

And yes, this was intentional. I need to include libc++'s version of `math.h` to get the correct set of symbols.


Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D60097/new/

https://reviews.llvm.org/D60097





More information about the libcxx-commits mailing list