This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
std::isnan<>() is broken on FreeBSD
- From: Lorenz Minder <lminder at gmx dot net>
- To: libstdc++ at gcc dot gnu dot org
- Date: Fri, 7 Jan 2005 21:06:05 +0100
- Subject: std::isnan<>() is broken on FreeBSD
Hi,
On FreeBSD 5.3, if I run the following test program (compiled w/ system gcc,
which is 3.4.2; or a hand-compiled current CVS snapshot):
#include <iostream>
#include <cmath>
int main(void)
{
std::cout << std::isnan(3.0) << '\n';
return 0;
}
I get a segfault:
lorinder$ g++ x.cc
lorinder$ ./a.out
Segmentation fault (core dumped)
There is no problem on Linux. The segfault happens as well if I add
-D_GLIBCXX_USE_C99_MATH.
The problem is, that __gnu_cxx::isnan<>() calls __gnu_cxx::__capture_isnan<>(),
which in turn recursively calls __gnu_cxx::isnan<>().
Indeed, FreeBSD's math.h contains the following snippet:
#define isnan(x) \
((sizeof (x) == sizeof (float)) ? isnanf(x) \
: (sizeof (x) == sizeof (double)) ? isnan(x) \
: __isnanl(x))
So, isnan() is both a macro and a function taking a double. If my
understanding is correct, __capture_isnan() calls __gnu_cxx::isnan() instead of
::isnan().
I am well aware that std::isnan() is probably not strictly standard C++ (since
isnan is new in C99), but I'd consider it a quality of implementation issue to
have it working if it is available.
Should I file a PR?
Regards,
--Lorenz