On 12/31/18 9:03 AM, Liu Hao wrote:
在 2018/12/31 2:56, Jacek Caban 写道:
Hello,

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
There is `/Za` but I haven't used it ever.


Good catch, I didn't know that. I checked how it affects math declarations and it indeed has some effect. It disables some (still, less than we do) declarations in strict C mode. It uses __STDC__ macro for that, which is not defined for strict C++, so my patch matches that more closely.


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__.

Yes, I think this bad, but it is how GCC behaves. Is it really necessary
to check for `__cplusplus`? It looks to me that the GNU C++ compiler
i.e. `__GNUG__` should be checked instead.


We could, but that's not my point. If other toolchain always declare those extensions in C++, this practically becomes a standard that may make sense for us to follow.

I grep'd over libstdc++ headers for `M_PI` and found no results. Which
declaration was it that caused the failure?


I chose M_PI as an example. It's not libstdc++ that caused issues in cases I mentioned, it's a similar assumption in Mozilla code. See:

https://gcc.gnu.org/onlinedocs/libstdc++/faq.html#faq.predefined

for an explanation about libstdc++.


Thanks,

Jacek



_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to