Blob Blame History Raw
Subject: math.h: Don't skip non-standard declarations in strict C++ mode.

We currently have a few checks for strict more in our math.h. It guards 
some non-standard (or at least not present in requested standard 
version) declarations. Some of those are pretty standard things like 
M_PI, others are Windows-specific, like underscored versions of standard 
functions. This causes some problems like [1] or [2] when one tries to 
build with -std=c++...

AFAIK, MSVC doesn't have a counterpart of strict standard more, so an 
assumption that those declarations are always present is valid among 
them. To mimic that, we could just remove __STRICT_ANSI__ checks. My 
patch does not go so far. I used a safer and less controversial approach 
and concentrated on C++ only.

On Linux, g++ defines _GNU_SOURCE because libstdc++ relies on some 
declarations that would be otherwise not be present (clang and libc++ 
are the same AFAIK). I didn't check, but saw an info that it does 
similar things on other platforms. That causes C++ to assume that things 
like M_PI is present even if specified standard would mean otherwise. 
The attached patch makes such assumption valid on mingw-w64 by 
explicitly checking for C++ in places checking __STRICT_ANSI__.

---

https://sourceforge.net/p/mingw-w64/mailman/message/36505053/

diff --git a/mingw-w64-headers/crt/math.h b/mingw-w64-headers/crt/math.h
index 658abc80..2d266995 100644
--- a/mingw-w64-headers/crt/math.h
+++ b/mingw-w64-headers/crt/math.h
@@ -23,7 +23,7 @@ struct _exception;
 #define	_TLOSS		5	/* total loss of precision */
 #define	_PLOSS		6	/* partial loss of precision */
 
-#ifndef __STRICT_ANSI__
+#if !defined(__STRICT_ANSI__) || defined(__cplusplus)
 #ifndef	NO_OLDNAMES
 
 #define	DOMAIN		_DOMAIN
@@ -36,7 +36,7 @@ struct _exception;
 #endif
 #endif
 
-#if !defined(__STRICT_ANSI__) || defined(_POSIX_C_SOURCE) || defined(_POSIX_SOURCE) || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) || defined(_USE_MATH_DEFINES)
+#if !defined(__STRICT_ANSI__) || defined(__cplusplus) || defined(_POSIX_C_SOURCE) || defined(_POSIX_SOURCE) || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) || defined(_USE_MATH_DEFINES)
 #define M_E		2.7182818284590452354
 #define M_LOG2E		1.4426950408889634074
 #define M_LOG10E	0.43429448190325182765
@@ -52,7 +52,7 @@ struct _exception;
 #define M_SQRT1_2	0.70710678118654752440
 #endif
 
-#ifndef __STRICT_ANSI__
+#if !defined(__STRICT_ANSI__) || defined(__cplusplus)
 /* See also float.h  */
 #ifndef __MINGW_FPCLASS_DEFINED
 #define __MINGW_FPCLASS_DEFINED 1
@@ -263,7 +263,7 @@ extern "C" {
 #define EDOM 33
 #define ERANGE 34
 
-#ifndef __STRICT_ANSI__
+#if !defined(__STRICT_ANSI__) || defined(__cplusplus)
 
 #ifndef _COMPLEX_DEFINED
 #define _COMPLEX_DEFINED
@@ -1088,7 +1088,7 @@ __MINGW_EXTENSION long long __cdecl llrintl (long double);
   extern float __cdecl nanf(const char *tagp);
   extern long double __cdecl nanl(const char *tagp);
 
-#ifndef __STRICT_ANSI__
+#if !defined(__STRICT_ANSI__) || defined(__cplusplus)
 #define _nan() nan("")
 #define _nanf() nanf("")
 #define _nanl() nanl("")