[libcxx-commits] [PATCH] D60097: Fix implementation of ::abs and std::abs LWG 2192.
Khem Raj via Phabricator via libcxx-commits
libcxx-commits at lists.llvm.org
Sun Aug 4 16:12:26 PDT 2019
raj.khem 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:
> EricWF wrote:
> > 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.
> if a system header is included then whatever that includes should remain within system headers search path, user is doing `#include <stdlib.h>`
> and includes local math.h via include "math.h" not <math.h>, however the problem is clang searching for math.h requested by stdlib.h then goes into user header search paths specified via `-I`
to add a bit more, here I think the perceived problem is indirect inclusion of user defined header via a system header
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