This is pretty much the same as https://stackoverflow.com/questions/13883199/g-mingw-c11-and-sse
I do have the latest MinGW release and executing echo "#include <cmath>" | g++ -x c++ - -msse -mfpmath=sse -o /dev/null yields in
c:\mingw\lib\gcc\mingw32\6.3.0\include\c++\cmath:1101:11: error:
'::double_t' has not been declared using ::double_t;c:\mingw\lib\gcc\mingw32\6.3.0\include\c++\cmath:1102:11: error:
'::float_t' has not been declared using ::float_t;
According to the other question this was a bug from 2012 which is supposed to be fixed. However it seems to be still there.
A bit of digging brought me to the realization that __FLT_EVAL_METHOD__ is defined but empty which causes undefined float_t/double_t.
Omitting the -mfpmath=sse option makes the problem disappear but that is not sensible.
MinGW version is 5.0.1 and gcc is 6.3.0.
Thanks for reporting this; frankly, I'm astonished that it has taken nine and a half years, since Danny Smith introduced the
double_tandfloat_ttypedefs into<math.h>, for anyone to get around to filing such a report, and even then, only after what appears to me to be a regression inGCC-6has increased the visibility of the underlying bug.First, let's address that
GCC-6regression, (for which you should file a report on GCC's upstream bug tracker -- https://gcc.gnu.org/bugzilla): the combination of-msseand-mfpmath=sse, as used in your command example, causesGCC-6to define its internal__FLT_EVAL_METHOD__to-1, (I can neither reproduce nor confirm your claim that it is defined but "empty"), whereas with releases fromGCC-3toGCC-5, this same combination of options cause__FLT_EVAL_METHOD__to assume a value of zero, (which I think is correct;-1indicates an indeterminate__FLT_EVAL_METHOD__state, which arises with the earlier GCC versions only when-mfpmathis indeterminately specified as387,sse,387+sse, orboth... the latter two equivalents being unsupported inGCC-3). FWIW, if you specify the combination-msseN -mfpmath=sseforN = 2,3, or4, then__FLT_EVAL_METHOD__will be correctly specified as zero.Secondly, in spite of your issue arising out of a
GCC-6regression, there is an underlying MinGW.org bug; in<math.h>I see:The problem with this is that it presumes that
__FLT_EVAL_METHOD__, if defined, will always assume a value of0,1, or2; it completely ignores the (legitimate) case ofGCCdefining__FLT_EVAL_METHOD__with a value of-1. We can, (and should), fix that, but code compiled with the combination of-msse -mfpmath=sseoptions, as in your example case, will remain vulnerable to the effects of theGCC-6regression, and will likely misbehave, if thedouble_t, orfloat_tdata types are actually used; (note that this regression will also affectCcode, in the (perhaps less likely) event that these data types are used).Finally, as an aside, I assume that your reference to "the other question" relates to your StackOverflow reference. This is a perfect illustration of the utter futility of discussing bugs in that particular forum: not only is that entire site top heavy with disinformation, but those participating in such discussions are unlikely to be in any position to fix the underlying issue, and are also unlikely to report the problem to anyone who actually is in such a position. How could this problem have been fixed in 2012, in MinGW.org code, when no one here was ever made aware that the problem even existed?
Last edit: Keith Marshall 2017-10-19
Thank you for your analysis and explanation.
First I reported this as a bug in GCC and got shot down quickly with the explanation that without
-msse2the correct value is indeed -1. If you think this is wrong, please participate in the discussion at https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82626Besides that, yes the -1 case should be handled. But please also note, that other negative values are possible too (http://en.cppreference.com/w/c/types/limits/FLT_EVAL_METHOD).
And lastly: My mistake there. It seems someone from the MinGW64 team answered to the SO post and also fixed it in their code. Probably confused this with MinGW(32).
But besides that it is a good way of asking for help first, as most likely it is a user error not a compiler bug. (Just read the comment on my (unrelated) question
"And even a bug in g++ is more unlikely than you did something wrong.") And if people find that it is a compiler bug, one can still go to the bugtrackers.This is way off topic here, but...
Sorry, but I can't agree with you there ... unless you are willing to accept that most of those who respond are likely to be ill-informed SO reputation seekers, who will say anything in an attempt to attract reputation-enhancing votes; it doesn't matter how accurate the information they provide is, (because those who vote know no better anyway). Around 90% of the MinGW related content on SO is utter garbage, and its quality is roughly inversely proportional to the reputation of those providing it.
They could, but in my experience they rarely do ... probably because they lack the confidence in their ability to adequately diagnose the attendant issues, and they don't want to expose their ignorance.
Much better, by far, to avoid such sites as SO entirely, and direct questions to the mailing lists or fora which are specific to the projects in question, where you will stand a much better chance of getting informed, and accurate responses.
Diff:
Attached patch should resolve the MinGW.org aspect of this bug. GCC-6 regression remains, (and may never be resolved, because GCC maintainers seem reluctant to acknowledge their culpability). Please note that, for the specific combination of
-msse -mfpmath=sseoptions, bothfloat_tanddouble_twill default to 80-bitlong doubleprecision, which may not be what you want, but it is the best compromise we can offer, unless GCC maintainers can be persuaded to DTRT.Last edit: Keith Marshall 2017-10-20
Diff:
I believe that [7cd51d] resolves this, to the extent we can achieve; it will be included in the next release.
Related
Commit: [7cd51d]