I have a very similar problem to this one: How to resolve "fpclassify': ambiguous call to overloaded function
I have a large project with about 100 cpp-files and 100 header-files that work fine in Codeblocks using GNU GCC compiler, but I want to migrate the project to VS19. It seems to work fine except for one error: "fpclassify': ambiguous call to overloaded function
The error list in VS19 tells me it is located in corecrt_math.h
on a return value at line 415:
template <class _Ty>
_Check_return_ inline bool isnan(_In_ _Ty _X) throw()
{
return fpclassify(_X) == FP_NAN;
}
When looking into my code I see that I use std::isna
in 13 files, 24 locations (the error list does not refer to these places at all). However, unlike the problem that I linked to above, I do not see that I check if an int
is na
anywhere. Instead I have cases like this:
if (std::isnan(static_cast<double> (min)) && std::isnan(static_cast<double> (max)))
simulation_error("Error: No limits");
Where min
and max
are defined as const double & min = NAN
and const double & max = NAN
(min
and max
are set in the constructor).
Do you have any idea on how to find the error and how to solve it? I tried many hours yesterday - without any success.
Edit:
Full error message below:
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\ucrt\corecrt_math.h(415,1): error C2668: 'fpclassify': ambiguous call to overloaded function
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\ucrt\corecrt_math.h(300,31): message : could be 'int fpclassify(long double) noexcept'
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\ucrt\corecrt_math.h(295,31): message : or 'int fpclassify(double) noexcept'
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\ucrt\corecrt_math.h(290,31): message : or 'int fpclassify(float) noexcept'
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\ucrt\corecrt_math.h(415,1): message : while trying to match the argument list '(_Ty)'
1> with
1> [
1> _Ty=bool
1> ]
1>C:\Users\Name\Documents\C++\Project name\Project name\src\module.cpp(668): message : see reference to function template instantiation 'bool isnan<bool>(_Ty) noexcept' being compiled
1> with
1> [
1> _Ty=bool
1> ]
Which refers to:
std::vector<double> stoprule_rel;,
if (!(std::isnan(static_cast<double> (stoprule_rel[i])
The error message like fpclassify': ambiguous call to overloaded function
is always accompanied by notes. For example, for a simple program
#include <cmath>
int main() {
std::isnan(5);
}
VS complains:
corecrt_math.h(415): error C2668: 'fpclassify': ambiguous call to overloaded function
corecrt_math.h(300): note: could be 'int fpclassify(long double) throw()'
corecrt_math.h(295): note: or 'int fpclassify(double) throw()'
corecrt_math.h(290): note: or 'int fpclassify(float) throw()'
corecrt_math.h(415): note: while trying to match the argument list '(_Ty)'
with [ _Ty=int ]
<source>(3): note: see reference to function template instantiation 'bool isnan<int>(_Ty) throw()' being compiled
with [ _Ty=int ]
From these notes we can infer that _Ty
is int
and that std::nan
was called on the line 3 of our source code. Take a look at the full compiler output for your compilation, it will tell you the exact place in your code where the error is triggered.