summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--libcxx/include/math.h12
-rw-r--r--libcxx/test/libcxx/depr/depr.c.headers/math_h.sh.cpp23
2 files changed, 33 insertions, 2 deletions
diff --git a/libcxx/include/math.h b/libcxx/include/math.h
index 8c30ba85d22..1476772351c 100644
--- a/libcxx/include/math.h
+++ b/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 @@ long double truncl(long double x);
#pragma GCC system_header
#endif
-#include_next <math.h>
-
#ifdef __cplusplus
// We support including .h headers inside 'extern "C"' contexts, so switch
diff --git a/libcxx/test/libcxx/depr/depr.c.headers/math_h.sh.cpp b/libcxx/test/libcxx/depr/depr.c.headers/math_h.sh.cpp
new file mode 100644
index 00000000000..8048865c34b
--- /dev/null
+++ b/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
OpenPOWER on IntegriCloud