[PATCH] D43579: [libcxx] Do not include the C math.h header before __config

Mikhail Maltsev via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Feb 21 08:08:08 PST 2018


miyuki created this revision.
miyuki added a reviewer: mclow.lists.
Herald added a reviewer: EricWF.

Certain C libraries require configuration macros defined in __config
to provide the correct functionality for libc++. This patch ensures
that the C header math.h is always included after the __config
header. It also adds a Windows-specific #if guard for the case when
the C math.h file is included the second time, as suggested by
Marshall in https://reviews.llvm.org/rL323490.

Fixes PR36382.


https://reviews.llvm.org/D43579

Files:
  include/math.h


Index: include/math.h
===================================================================
--- include/math.h
+++ include/math.h
@@ -8,16 +8,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-// This include lives outside the header guard in order to support an MSVC
-// extension which allows users to do:
-//
-// #define _USE_MATH_DEFINES
-// #include <math.h>
-//
-// and receive the definitions of mathematical constants, even if <math.h>
-// has previously been included.
-#include_next <math.h>
-
 #ifndef _LIBCPP_MATH_H
 #define _LIBCPP_MATH_H
 
@@ -308,6 +298,8 @@
 #pragma GCC system_header
 #endif
 
+#include_next <math.h>
+
 #ifdef __cplusplus
 
 // We support including .h headers inside 'extern "C"' contexts, so switch
@@ -1494,4 +1486,18 @@
 
 #endif // __cplusplus
 
+#else // _LIBCPP_MATH_H
+
+// This include lives outside the header guard in order to support an MSVC
+// extension which allows users to do:
+//
+// #define _USE_MATH_DEFINES
+// #include <math.h>
+//
+// and receive the definitions of mathematical constants, even if <math.h>
+// has previously been included.
+#if defined(_LIBCPP_MSVCRT) && defined(_USE_MATH_DEFINES)
+#include_next <math.h>
+#endif
+
 #endif  // _LIBCPP_MATH_H


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D43579.135264.patch
Type: text/x-patch
Size: 1259 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180221/b7865522/attachment.bin>


More information about the cfe-commits mailing list