[PATCH] D42403: libcxx: Move #include_next <math.h> out of header guard in wrapper header.

Peter Collingbourne via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 25 16:02:17 PST 2018


pcc updated this revision to Diff 131520.
pcc added a comment.

- Address review comments


https://reviews.llvm.org/D42403

Files:
  libcxx/include/math.h
  libcxx/test/libcxx/depr/depr.c.headers/math_h.sh.cpp


Index: libcxx/test/libcxx/depr/depr.c.headers/math_h.sh.cpp
===================================================================
--- /dev/null
+++ libcxx/test/libcxx/depr/depr.c.headers/math_h.sh.cpp
@@ -0,0 +1,23 @@
+//===----------------------------------------------------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// RUN: %compile -fsyntax-only
+
+#ifdef _MSC_VER
+
+#include <math.h>
+
+#define _USE_MATH_DEFINES
+#include <math.h>
+
+#ifndef M_PI
+#error M_PI not defined
+#endif
+
+#endif
Index: libcxx/include/math.h
===================================================================
--- libcxx/include/math.h
+++ libcxx/include/math.h
@@ -8,6 +8,16 @@
 //
 //===----------------------------------------------------------------------===//
 
+// 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
 
@@ -298,8 +308,6 @@
 #pragma GCC system_header
 #endif
 
-#include_next <math.h>
-
 #ifdef __cplusplus
 
 // We support including .h headers inside 'extern "C"' contexts, so switch


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D42403.131520.patch
Type: text/x-patch
Size: 1558 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180126/85608729/attachment.bin>


More information about the llvm-commits mailing list