[libc++] Remove _LIBCPP_HAS_NO_LONG_LONG in favour of using_if_exists
_LIBCPP_HAS_NO_LONG_LONG was only defined on FreeBSD. Instead, use the
using_if_exists attribute to skip over declarations that are not available
on the base system. Note that there's an annoying limitation that we can't
conditionally define a function based on whether the base system provides
a function, so for example we still need preprocessor logic to define the
abs() and div() overloads.
Differential Revision: https://reviews.llvm.org/D108630
NOKEYCHECK=True
GitOrigin-RevId: c137a0754c4e13181c226359687ae9f3d8b488f0
diff --git a/include/stdlib.h b/include/stdlib.h
index 242eedc..a2b7cbd 100644
--- a/include/stdlib.h
+++ b/include/stdlib.h
@@ -96,10 +96,14 @@
extern "C++" {
// abs
-#undef abs
-#undef labs
-#ifndef _LIBCPP_HAS_NO_LONG_LONG
-#undef llabs
+#ifdef abs
+# undef abs
+#endif
+#ifdef labs
+# undef labs
+#endif
+#ifdef llabs
+# undef llabs
#endif
// MSVCRT already has the correct prototype in <stdlib.h> if __cplusplus is defined
@@ -107,11 +111,9 @@
inline _LIBCPP_INLINE_VISIBILITY long abs(long __x) _NOEXCEPT {
return __builtin_labs(__x);
}
-#ifndef _LIBCPP_HAS_NO_LONG_LONG
inline _LIBCPP_INLINE_VISIBILITY long long abs(long long __x) _NOEXCEPT {
return __builtin_llabs(__x);
}
-#endif // _LIBCPP_HAS_NO_LONG_LONG
#endif // !defined(_LIBCPP_MSVCRT) && !defined(__sun__)
#if !defined(__sun__)
@@ -131,10 +133,14 @@
// div
-#undef div
-#undef ldiv
-#ifndef _LIBCPP_HAS_NO_LONG_LONG
-#undef lldiv
+#ifdef div
+# undef div
+#endif
+#ifdef ldiv
+# undef ldiv
+#endif
+#ifdef lldiv
+# undef lldiv
#endif
// MSVCRT already has the correct prototype in <stdlib.h> if __cplusplus is defined
@@ -142,12 +148,12 @@
inline _LIBCPP_INLINE_VISIBILITY ldiv_t div(long __x, long __y) _NOEXCEPT {
return ::ldiv(__x, __y);
}
-#ifndef _LIBCPP_HAS_NO_LONG_LONG
+#if !(defined(__FreeBSD__) && !defined(__LONG_LONG_SUPPORTED))
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
#endif // _LIBCPP_MSVCRT / __sun__
} // extern "C++"
#endif // __cplusplus