mateidavid / zstr

A C++ header-only ZLib wrapper
MIT License
295 stars 71 forks source link

call to implicitly-deleted copy constructor of 'zstr::ifstream' #59

Closed jmakov closed 1 year ago

jmakov commented 1 year ago

I'm trying to use zstr::ifstream with a CSV parser but I'm getting:

//from the IDE (clion)
In template: call to implicitly-deleted copy constructor of 'zstr::ifstream' error occurred here 
in instantiation of member function 'csv::internals::StreamParser<zstr::ifstream>::StreamParser' requested here 
in instantiation of function template specialization 'csv::CSVReader::CSVReader<zstr::ifstream, 0>' requested here 
copy constructor of 'ifstream' is implicitly deleted because base 
class 'detail::strict_fstream_holder<strict_fstream::ifstream>' has a deleted copy constructor 
copy constructor of 'strict_fstream_holder<strict_fstream::ifstream>' is implicitly deleted because 
field '_fs' has a deleted copy constructor copy constructor of 'ifstream' is implicitly deleted because 
base class 'std::ifstream' (aka 'basic_ifstream<char>') has a deleted copy constructor 'basic_ifstream' has 
been explicitly marked deleted here

//and from the compiler
lib/zstr/src/zstr.hpp:411:7: error: use of deleted function ‘zstr::detail::strict_fstream_holder<strict_fstream::ifstream>::strict_fstream_holder(const zstr::detail::strict_fstream_holder<strict_fstream::ifstream>&)’
lib/zstr/src/zstr.hpp:400:8: note: ‘zstr::detail::strict_fstream_holder<strict_fstream::ifstream>::strict_fstream_holder(const zstr::detail::strict_fstream_holder<strict_fstream::ifstream>&)’ is implicitly deleted because the default definition would be ill-formed:
  400 | struct strict_fstream_holder
      |        ^~~~~~~~~~~~~~~~~~~~~
lib/zstr/src/zstr.hpp:400:8: error: use of deleted function ‘strict_fstream::ifstream::ifstream(const strict_fstream::ifstream&)’
lib/zstr/src/strict_fstream.hpp:177:7: error: use of deleted function ‘std::basic_ifstream<_CharT, _Traits>::basic_ifstream(const std::basic_ifstream<_CharT, _Traits>&) [with _CharT = char; _Traits = std::char_traits<char>]’
lib/zstr/src/strict_fstream.hpp:177:7: error: use of deleted function ‘std::basic_ios<_CharT, _Traits>::basic_ios(const std::basic_ios<_CharT, _Traits>&) [with _CharT = char; _Traits = std::char_traits<char>]’
  177 | class ifstream
      |       ^~~~~~~~
//this works
std::ifstream file(fp, std::ios::binary);
csv::CSVReader reader(file, csv_format);

//doesn't compile - getting the error above
zstr::ifstream file(fp, std::ios::binary);
csv::CSVReader reader(file, csv_format);

Any help appreciated.

behrisch commented 1 year ago

I had the same problem here when compiling with CentOS 7. The compiler is too old, see https://cplusplus.com/forum/unices/238480/. I simply removed the open function since I don't use it.

ferdymercury commented 1 year ago

Thanks! Feel free to provide a PR where you deactivate that function with an ifdef gnu-version < N

jmakov commented 1 year ago

@behrisch upgrading to latest GCC solves the issue for me, thank you very much! I'll leave the issue open if somebody decides to open a PR.