Home > Back-end >  Different results of std::isinf for different types and different compilers
Different results of std::isinf for different types and different compilers

Time:11-08

Compiling with MSVC(v19.33), this does not compile (C2668 ambiguous call to overloaded function):

std::cout << std::isinf(0) << std::endl;

But this compiles:

std::cout << std::isinf(0.0) << std::endl;

However, in cppreference.com, it says:

  1. A set of overloads or a function template accepting the arg argument of any integral type. Equivalent to (2) (the argument is cast to double).

It seems like the function has existed in the standard since C 11.

If I understood correctly, the first code should be equivalent to the second one, shouldn't it? Does this mean MSVC hasn't implemented the overloaded functions yet, or am I missing something?

(In contrast, if I use gcc or clang, the above examples compile without problems).

CodePudding user response:

In the Microsoft's implementation, the definition of the isinf is as follows (copied from here):

template <class _Ty>
_Check_return_ inline bool isinf(_In_ _Ty _X) throw()
{
    return fpclassify(_X) == FP_INFINITE;
}

The problem with Microsoft's fpclassify is the missing overload for integral types. For more details, see:

'fpclassify': ambiguous call to overloaded function.

I agree with the opinion that MSVC is wrong here (however, it seems that they don't care).

  • Related