From 6b5c08ab347ee1853eb7774443f28a82203f3ad0 Mon Sep 17 00:00:00 2001 From: Peter Collingbourne Date: Fri, 26 Jan 2018 01:19:23 +0000 Subject: [PATCH] libcxx: Move #include_next out of header guard in wrapper header. Code on Windows expects to be able to do: #define _USE_MATH_DEFINES #include and receive the definitions of mathematical constants, even if has previously been included. To support this scenario, re-include every time the wrapper header is included. Differential Revision: https://reviews.llvm.org/D42403 git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@323490 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/math.h | 12 ++++++++-- test/libcxx/depr/depr.c.headers/math_h.sh.cpp | 23 +++++++++++++++++++ 2 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 test/libcxx/depr/depr.c.headers/math_h.sh.cpp diff --git a/include/math.h b/include/math.h index 8c30ba85d..147677235 100644 --- a/include/math.h +++ b/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 +// +// and receive the definitions of mathematical constants, even if +// has previously been included. +#include_next + #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 - #ifdef __cplusplus // We support including .h headers inside 'extern "C"' contexts, so switch diff --git a/test/libcxx/depr/depr.c.headers/math_h.sh.cpp b/test/libcxx/depr/depr.c.headers/math_h.sh.cpp new file mode 100644 index 000000000..8048865c3 --- /dev/null +++ b/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 + +#define _USE_MATH_DEFINES +#include + +#ifndef M_PI +#error M_PI not defined +#endif + +#endif