From d42dc2011076bde10aac414aee100b0db88accb4 Mon Sep 17 00:00:00 2001
From: Iain Sandoe <iain@sandoe.co.uk>
Date: Sun, 27 Jul 2014 19:48:56 +0100
Subject: [PATCH] [libcxx] Updated version of David Fang's wrapper for
 math.h

We now use the local math.h wrapper so that the change is
effective wherever math.h is used.
---
 libcxx/include/cmath  |  1 -
 libcxx/include/math.h | 18 ++++++++++++++++++
 2 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/libcxx/include/cmath b/libcxx/include/cmath
index ffb1c46c7b6..8ba7bcd3bf5 100644
--- a/libcxx/include/cmath
+++ b/libcxx/include/cmath
@@ -301,7 +301,6 @@ long double    truncl(long double x);
 
 */
 
-#include <__config>
 #include <math.h>
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
diff --git a/libcxx/include/math.h b/libcxx/include/math.h
index 3cc72aa2791..831fff10d37 100644
--- a/libcxx/include/math.h
+++ b/libcxx/include/math.h
@@ -298,8 +298,26 @@ long double    truncl(long double x);
 #pragma GCC system_header
 #endif
 
+// The C++11 standard requires C99, but whether or not __STDC_VERSION__
+// is accordingly set is implementation-defined.
+// on darwin10: C99 is explicltly required to enable long long returning
+// functions, like llrint and llround.
+// Alternatively, undefine __STRICT_ANSI__ for those symbols.
+// This is just a convenient, isolated workaround.
+#if defined(__APPLE__) && (__cplusplus >= 201101L) \
+    && !defined(__STDC_VERSION__) && defined(__STRICT_ANSI__)
+#define	__IMPLICIT_STDC_VERSION_C99__
+#undef	__STRICT_ANSI__
+#endif
+
 #include_next <math.h>
 
+#ifdef	__IMPLICIT_STDC_VERSION_C99__
+// Undo the temporary change made above.
+#define	__STRICT_ANSI__
+// __IMPLICIT_STDC_VERSION_C99__ remains defined as evidence of what happened
+#endif
+
 #ifdef __cplusplus
 
 // We support including .h headers inside 'extern "C"' contexts, so switch
