How to fix C++ boost/array.hpp:118:61: error: expected primary-expression before ‘,’ token
In a legacy C++ project that is using Boost ProgramOptions. trying to compile it will yield this error message:
In file included from /usr/include/boost/lexical_cast/detail/converter_lexical.hpp:50:0,
from /usr/include/boost/lexical_cast/try_lexical_convert.hpp:42,
from /usr/include/boost/lexical_cast.hpp:32,
from /usr/include/boost/program_options/value_semantic.hpp:14,
from /usr/include/boost/program_options/options_description.hpp:13,
from /usr/include/boost/program_options.hpp:15,
from /home/uli/dev/myproject/datasplit.cpp:15:
/usr/include/boost/array.hpp: In member function ‘T& boost::array<T, N>::operator[](boost::array<T, N>::size_type)’:
/usr/include/boost/array.hpp:118:61: error: expected primary-expression before ‘,’ token
return BOOST_ASSERT_MSG( i < N, "out of range" ), elems[i];
I didn’t find a satisfying way to fix this issue but it can be worked around fixing the issue in the source file:
First, open /usr/include/boost/array.hpp
in your favourite editor as root (sudo!). I use nano
.
Then, go to line 118 which reads:
return BOOST_ASSERT_MSG( i < N, "out of range" ), elems[i];
Replace that line by
BOOST_ASSERT_MSG( i < N, "out of range" );
return elems[i];
Also, 4 lines below what we just edited you’ll find another instance of
return BOOST_ASSERT_MSG( i < N, "out of range" ), elems[i];
Also replace that by
BOOST_ASSERT_MSG( i < N, "out of range" );
return elems[i];
Now. save the file and close your editor. Your code should compile now.