https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70609
--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> --- The problem is due to my lazy approach to copying the file: __gnu_cxx::stdio_filebuf<char> sbin(in.fd, std::ios::in); __gnu_cxx::stdio_filebuf<char> sbout(out.fd, std::ios::out); if ( !(std::ostream(&sbout) << &sbin) ) { ec = std::make_error_code(std::errc::io_error); return false; } The condition is false when no bytes are copied. We just want to make that code conditional with: if (from_st->st_size) That function should also check the result of ::close(fd), on at least the target file.