[Bug c++/54130] Recognize builtins with bool return type

glisse at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Wed Aug 1 05:51:00 GMT 2012


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54130

--- Comment #8 from Marc Glisse <glisse at gcc dot gnu.org> 2012-08-01 05:51:26 UTC ---
(In reply to comment #7)
> C++ may also require functions rather than macros in various cases.  It's 
> the job of the libstdc++ headers, provided by GCC, to provide a (probably 
> inline) isnan function meeting the C++ requirements, replacing the C 
> library's macro when building for C++.  Likewise all the other cases where 
> C++ and C requirements for standard headers differ: the fix is in headers 
> in one form or another rather than built in to the compiler.

That makes solving PR 48891 quite hard. glibc provides a function int
isnan(double), which is illegal in C++. I was thinking of asking them to change
the return type to bool in C++, then libstdc++ could just use that function
(having gcc recognize isnan as a builtin is not a prerequisite for this, but it
would avoid a regression). Another solution I can think of is that libstdc++
provides a math.h wrapper that does #define isnan __removed_isnan, then
#include_next <math.h>, #undef isnan, and finally provides its own declaration
of isnan (it might actually be better to do that first). If the C library
doesn't #undef isnan and then declare an isnan function, that may work, but it
may also break stuff if the C library uses isnan. I could also ask glibc to not
declare the isnan function at all in C++, but that's a bit strange and other C
libraries may define an isnan function.

All of those ideas are rather fragile. If you have better ideas about PR 48891,
please do tell.


Note also that in C, we are currently failing to optimize this to a constant:
#include <math.h>
int f(){return isnan(3);}



More information about the Gcc-bugs mailing list