Skip to content

Commit 0aa71a4

Browse files
committedJan 26, 2018
libcxx: Move #include_next <math.h> out of header guard in wrapper header.
Code on Windows expects to be able to do: #define _USE_MATH_DEFINES #include <math.h> and receive the definitions of mathematical constants, even if <math.h> has previously been included. To support this scenario, re-include <math.h> every time the wrapper header is included. Differential Revision: https://reviews.llvm.org/D42403 llvm-svn: 323490
1 parent c0e9bee commit 0aa71a4

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed
 

‎libcxx/include/math.h

+10-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,16 @@
88
//
99
//===----------------------------------------------------------------------===//
1010

11+
// This include lives outside the header guard in order to support an MSVC
12+
// extension which allows users to do:
13+
//
14+
// #define _USE_MATH_DEFINES
15+
// #include <math.h>
16+
//
17+
// and receive the definitions of mathematical constants, even if <math.h>
18+
// has previously been included.
19+
#include_next <math.h>
20+
1121
#ifndef _LIBCPP_MATH_H
1222
#define _LIBCPP_MATH_H
1323

@@ -298,8 +308,6 @@ long double truncl(long double x);
298308
#pragma GCC system_header
299309
#endif
300310

301-
#include_next <math.h>
302-
303311
#ifdef __cplusplus
304312

305313
// We support including .h headers inside 'extern "C"' contexts, so switch
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// The LLVM Compiler Infrastructure
4+
//
5+
// This file is dual licensed under the MIT and the University of Illinois Open
6+
// Source Licenses. See LICENSE.TXT for details.
7+
//
8+
//===----------------------------------------------------------------------===//
9+
10+
// RUN: %compile -fsyntax-only
11+
12+
#ifdef _MSC_VER
13+
14+
#include <math.h>
15+
16+
#define _USE_MATH_DEFINES
17+
#include <math.h>
18+
19+
#ifndef M_PI
20+
#error M_PI not defined
21+
#endif
22+
23+
#endif

0 commit comments

Comments
 (0)
Please sign in to comment.