Microos Microos - 2 months ago 18
C++ Question

gcc-6 compile error: expected '(' before 'isnan'

I encountered a weird error that says:

spams/linalg/linalg.h: In member function 'void Matrix<T>::eigLargestSymApprox(const Vector<T>&, Vector<T>&) const':
spams/linalg/linalg.h:1681:10: error: expected '(' before 'isnan'

if isnan(lambda) {
^~~~~


And I then go to check the code where the complier refer to:

if isnan(lambda) {
std::cerr << "eigLargestSymApprox failed" << std::endl;
exit(1);
}


It seems the problem of the function call of
isnan
.

Do you have any idea about it?

Answer

The expression in the if needs to be enclosed in parentheses:

if (std::isnan(lambda))

will fix it. Note that std::isnan was introduced in the C++11 standard.

Comments