[cfe-dev] libc++ std::isfinite() problem

Marshall Clow mclow.lists at gmail.com
Mon Jan 14 07:38:28 PST 2013


On Jan 14, 2013, at 5:25 AM, Kal Conley <kcconley at gmail.com> wrote:

> Hi,
> I am getting compile errors trying to compile code which tries to do
> something equivalent to std::isfinite((int)0). I get:
> 
> test.cc:27:3: error: no matching function for call to 'isfinite'
>  std::isfinite((int)0);
>  ^~~~~~~~~~~~~
> /usr/bin/../lib/c++/v1/cmath:376:1: note: candidate template ignored:
> substitution failure [with _A1 = int]
> isfinite(_A1 __x)
> 
> This compiles OK on all versions of libstdc++ that I have tried. Is
> libc++'s implementation correct here?

Looking at the C++ standard, std::isfinite is only defined thus:
	
	bool isfinite( float arg );
	bool isfinite( double arg );
	bool isfinite( long double arg );
[ Section 26.8 ]

So, I would say that, yes, libc++'s implementation is correct (to reject what you're trying to do)

> Should it be relying on templates
> and only allowing specializations that satisfy std::is_floating_point?

I don't see why not.

There's also an isfinite macro defined by the C standard.
It's defined to work on floating point types as well, but since it's a macro, type checking the parameter is harder/looser.
[ Section 7.12.3.2 of the C99 standard ]

-- Marshall

Marshall Clow     Idio Software   <mailto:mclow.lists at gmail.com>

A.D. 1517: Martin Luther nails his 95 Theses to the church door and is promptly moderated down to (-1, Flamebait).
        -- Yu Suzuki





More information about the cfe-dev mailing list