rmaprath updated this revision to Diff 69710.
rmaprath added a comment.

Re-spinning a new patch to test the waters.

@EricWF: Does this approach look OK?

/ Asiri


https://reviews.llvm.org/D23926

Files:
  include/__config
  include/math.h
  test/std/depr/depr.c.headers/math_h.pass.cpp
  test/std/numerics/c.math/cmath.pass.cpp
  test/std/numerics/complex.number/cmplx.over/proj.pass.cpp

Index: test/std/numerics/complex.number/cmplx.over/proj.pass.cpp
===================================================================
--- test/std/numerics/complex.number/cmplx.over/proj.pass.cpp
+++ test/std/numerics/complex.number/cmplx.over/proj.pass.cpp
@@ -34,7 +34,9 @@
 test(T x, typename std::enable_if<std::is_floating_point<T>::value>::type* = 0)
 {
     static_assert((std::is_same<decltype(std::proj(x)), std::complex<T> >::value), "");
+#if TEST_STD_VER > 3 || !_LIBCPP_STRICT_C99_COMPATIBILITY
     assert(std::proj(x) == proj(std::complex<T>(x, 0)));
+#endif
 }
 
 template <class T>
@@ -43,7 +45,9 @@
                                   !std::is_floating_point<T>::value>::type* = 0)
 {
     static_assert((std::is_same<decltype(std::proj(x)), std::complex<T> >::value), "");
+#if TEST_STD_VER > 3 || !_LIBCPP_STRICT_C99_COMPATIBILITY
     assert(std::proj(x) == proj(std::complex<T>(x, 0)));
+#endif
 }
 
 template <class T>
Index: test/std/numerics/c.math/cmath.pass.cpp
===================================================================
--- test/std/numerics/c.math/cmath.pass.cpp
+++ test/std/numerics/c.math/cmath.pass.cpp
@@ -752,6 +752,8 @@
     assert(std::isunordered(-1.0, 0.F) == false);
 }
 
+#if TEST_STD_VER > 3 || !_LIBCPP_STRICT_C99_COMPATIBILITY
+
 void test_acosh()
 {
     static_assert((std::is_same<decltype(std::acosh((float)0)), float>::value), "");
@@ -1479,6 +1481,8 @@
     assert(std::trunc(1) == 1);
 }
 
+#endif
+
 int main()
 {
     test_abs();
@@ -1516,6 +1520,7 @@
     test_islessgreater();
     test_isnan();
     test_isunordered();
+#if TEST_STD_VER > 3 || !_LIBCPP_STRICT_C99_COMPATIBILITY
     test_acosh();
     test_asinh();
     test_atanh();
@@ -1551,4 +1556,5 @@
     test_scalbn();
     test_tgamma();
     test_trunc();
+#endif
 }
Index: test/std/depr/depr.c.headers/math_h.pass.cpp
===================================================================
--- test/std/depr/depr.c.headers/math_h.pass.cpp
+++ test/std/depr/depr.c.headers/math_h.pass.cpp
@@ -750,6 +750,8 @@
     assert(isunordered(-1.0, 0.F) == false);
 }
 
+#if TEST_STD_VER > 3 || !_LIBCPP_STRICT_C99_COMPATIBILITY
+
 void test_acosh()
 {
     static_assert((std::is_same<decltype(acosh((float)0)), float>::value), "");
@@ -1455,6 +1457,8 @@
     assert(trunc(1) == 1);
 }
 
+#endif
+
 int main()
 {
     test_abs();
@@ -1492,6 +1496,7 @@
     test_islessgreater();
     test_isnan();
     test_isunordered();
+#if TEST_STD_VER > 3 || !_LIBCPP_STRICT_C99_COMPATIBILITY
     test_acosh();
     test_asinh();
     test_atanh();
@@ -1527,4 +1532,5 @@
     test_scalbn();
     test_tgamma();
     test_trunc();
+#endif
 }
Index: include/math.h
===================================================================
--- include/math.h
+++ include/math.h
@@ -302,6 +302,10 @@
 
 #ifdef __cplusplus
 
+#if __cplusplus >= 201103L || !_LIBCPP_STRICT_C99_COMPATIBILITY
+  #define __LIBCPP_USE_C99_MATH
+#endif
+
 // We support including .h headers inside 'extern "C"' contexts, so switch
 // back to C++ linkage before including these C++ headers.
 extern "C++" {
@@ -946,7 +950,7 @@
 
 // acosh
 
-#ifndef _LIBCPP_MSVCRT
+#if !defined(_LIBCPP_MSVCRT) && defined(__LIBCPP_USE_C99_MATH)
 inline _LIBCPP_INLINE_VISIBILITY float       acosh(float __lcpp_x) _NOEXCEPT       {return acoshf(__lcpp_x);}
 inline _LIBCPP_INLINE_VISIBILITY long double acosh(long double __lcpp_x) _NOEXCEPT {return acoshl(__lcpp_x);}
 
@@ -958,7 +962,7 @@
 
 // asinh
 
-#ifndef _LIBCPP_MSVCRT
+#if !defined(_LIBCPP_MSVCRT) && defined(__LIBCPP_USE_C99_MATH)
 inline _LIBCPP_INLINE_VISIBILITY float       asinh(float __lcpp_x) _NOEXCEPT       {return asinhf(__lcpp_x);}
 inline _LIBCPP_INLINE_VISIBILITY long double asinh(long double __lcpp_x) _NOEXCEPT {return asinhl(__lcpp_x);}
 
@@ -970,7 +974,7 @@
 
 // atanh
 
-#ifndef _LIBCPP_MSVCRT
+#if !defined(_LIBCPP_MSVCRT) && defined(__LIBCPP_USE_C99_MATH)
 inline _LIBCPP_INLINE_VISIBILITY float       atanh(float __lcpp_x) _NOEXCEPT       {return atanhf(__lcpp_x);}
 inline _LIBCPP_INLINE_VISIBILITY long double atanh(long double __lcpp_x) _NOEXCEPT {return atanhl(__lcpp_x);}
 
@@ -982,7 +986,7 @@
 
 // cbrt
 
-#ifndef _LIBCPP_MSVCRT
+#if !defined(_LIBCPP_MSVCRT) && defined(__LIBCPP_USE_C99_MATH)
 inline _LIBCPP_INLINE_VISIBILITY float       cbrt(float __lcpp_x) _NOEXCEPT       {return cbrtf(__lcpp_x);}
 inline _LIBCPP_INLINE_VISIBILITY long double cbrt(long double __lcpp_x) _NOEXCEPT {return cbrtl(__lcpp_x);}
 
@@ -994,7 +998,7 @@
 
 // copysign
 
-#if !defined(_VC_CRT_MAJOR_VERSION) || (_VC_CRT_MAJOR_VERSION < 12)
+#if defined(__LIBCPP_USE_C99_MATH) && (!defined(_VC_CRT_MAJOR_VERSION) || (_VC_CRT_MAJOR_VERSION < 12))
 inline _LIBCPP_INLINE_VISIBILITY float copysign(float __lcpp_x,
                                                 float __lcpp_y) _NOEXCEPT {
   return copysignf(__lcpp_x, __lcpp_y);
@@ -1005,6 +1009,7 @@
 }
 #endif
 
+#if defined(__LIBCPP_USE_C99_MATH)
 template <class _A1, class _A2>
 inline _LIBCPP_INLINE_VISIBILITY
 typename std::__lazy_enable_if
@@ -1020,9 +1025,9 @@
                      std::is_same<_A2, __result_type>::value)), "");
     return copysign((__result_type)__lcpp_x, (__result_type)__lcpp_y);
 }
+#endif
 
-#ifndef _LIBCPP_MSVCRT
-
+#if !defined(_LIBCPP_MSVCRT) && defined(__LIBCPP_USE_C99_MATH)
 // erf
 
 inline _LIBCPP_INLINE_VISIBILITY float       erf(float __lcpp_x) _NOEXCEPT       {return erff(__lcpp_x);}
Index: include/__config
===================================================================
--- include/__config
+++ include/__config
@@ -803,6 +803,17 @@
 #define _LIBCPP_CONSTEXPR_AFTER_CXX14
 #endif
 
+// Whether to assume a C99 compatible C library in C++03/98 modes. By default,
+// libc++ provides many C++11 operations in C++03/98 modes as extensions, some
+// of these extensions rely on the underlying C library providing C99 operations
+// even in C++03/98 modes. This flag forbids libc++ from making this assumption,
+// which means disabling those C++11 extensions in C++03/98 modes. Not providing
+// those extensions is better than trying to provide them and failing to compile
+// because the underlying C library is not C99 compatible.
+#ifndef _LIBCPP_STRICT_C99_COMPATIBILITY
+#  define _LIBCPP_STRICT_C99_COMPATIBILITY 0
+#endif
+
 #ifdef _LIBCPP_HAS_NO_RVALUE_REFERENCES
 #  define _LIBCPP_EXPLICIT_MOVE(x) _VSTD::move(x)
 #else
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to