Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

make fails with error "cannot convert ‘std::istream {aka std::basic_istream<char>}’ to ‘bool’ in return"

I'm trying to compile libgtextutils (required by the fastxtoolkit) from source. The './configure' command runs nicely, however subsequent 'make' command produces an error that I cannot resolve.

text_line_reader.cpp: In member function ‘bool TextLineReader::next_line()’:
text_line_reader.cpp:47:9: error: cannot convert ‘std::istream {aka std::basic_istream<char>}’ to ‘bool’ in return
  return input_stream ;
         ^~~~~~~~~~~~
make[3]: *** [text_line_reader.lo] Error 1
make[2]: *** [all-recursive] Error 1
make[1]: *** [all-recursive] Error 1
make: *** [all] Error 2

I'm on a Mac, OSX 10.11.6 (Intel)

Any suggestions that might solve this are highly appreciated.

like image 996
Steffan Daniel Bos-Haugen Avatar asked Jul 29 '16 12:07

Steffan Daniel Bos-Haugen


3 Answers

See the Porting to GCC 6 guide, which documents this as one of the changes you must deal with due to GCC 6 defaulting to C++14 mode instead of C++03 mode:

Cannot convert 'std::ostream' to 'bool'

As of C++11, iostream classes are no longer implicitly convertible to void* so it is no longer valid to do something like:

bool valid(std::ostream& os) { return os; }

Such code must be changed to convert the iostream object to bool explicitly, e.g. return (bool)os; or return static_cast<bool>(os);

Another option is to explicitly use -std=c++03 in your compiler flags to compile in C++03 mode, but it's better to fix the code. The fixes given above will make the code compatible with any C++ version.

like image 185
Jonathan Wakely Avatar answered Oct 16 '22 21:10

Jonathan Wakely


Another option is to override the C++ flags in the make command:

make CXXFLAGS='-std=c++03 -O1'

As noted above, fastx will also have a compilation error but it will compile if you pass it

make CXXFLAGS=-O1.

like image 28
ybendana Avatar answered Oct 16 '22 23:10

ybendana


This is because of using a newer version of gcc compiler (C++11).

Use static_cast<bool>() to resolve the issue.

example: change

success = move_group.move();

to

success = static_cast<bool>(move_group.move());
like image 20
Muthanna A. Alwahash Avatar answered Oct 16 '22 22:10

Muthanna A. Alwahash