[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 18:19:48 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
-#undef llabs
-#undef lldiv
-// 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);}
-inline _LIBCPP_INLINE_VISIBILITY long long abs(long long __x) _NOEXCEPT {return llabs(__x);}
-inline _LIBCPP_INLINE_VISIBILITY  ldiv_t div(     long __x,      long __y) _NOEXCEPT {return  ldiv(__x, __y);}
-inline _LIBCPP_INLINE_VISIBILITY lldiv_t div(long long __x, long long __y) _NOEXCEPT {return lldiv(__x, __y);}
-#endif // _LIBCPP_MSVCRT / __sun__ / _AIX
-}  // extern "C++"
+#include <math.h>
 #endif  // __cplusplus
raj.khem wrote:
> 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
The problem is that the user is doing something they shouldn't. From the C standard
> C11 7.1.2/3:
> "If a file with the same name as one of the [standard headers] is placed in any of the standard places that are searched for included source files, the behavior is undefined."




More information about the libcxx-commits mailing list