[Bug libstdc++/91653] ostream::operator<<(streambuf*) should fail the ostream when write output stream error but not

2019-09-10 Thread yhliang86 at hotmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91653

--- Comment #4 from yinghui  ---
(In reply to TC from comment #3)
> Looks NAD to me.
> 
> http://eel.is/c++draft/ostream.inserters#8.2 doesn't say that we set any bit
> in that case. Contrast with http://eel.is/c++draft/ostream.unformatted#3 and
> http://eel.is/c++draft/ostream.unformatted#5.2

so, seems like this is a bug of the c++ standard?
if an i/o function can't report failure on i/o operation failure, it can not be
used in any serious code.

[Bug libstdc++/91653] ostream::operator<<(streambuf*) should fail the ostream when write output stream error but not

2019-09-08 Thread yhliang86 at hotmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91653

--- Comment #2 from yinghui  ---
(In reply to Jonathan Wakely from comment #1)
> GCC 4.9.2 has been unsupported for several years.

but both the code and the problem still keeps exactly the same.

I have seen many c++ code write 'os << is.rdbuf()` as a stream copy idiom, and
this may silently write corrupted data in case like disk full.

[Bug libstdc++/91653] New: ostream::operator<<(streambuf*) should fail the ostream when write output stream error but not

2019-09-03 Thread yhliang86 at hotmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91653

Bug ID: 91653
   Summary: ostream::operator<<(streambuf*) should fail the
ostream when write output stream error but not
   Product: gcc
   Version: 4.9.2
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: libstdc++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: yhliang86 at hotmail dot com
  Target Milestone: ---

bits/ostream.tcc
 operator<<(__streambuf_type* __sbin):
   if (!__copy_streambufs(__sbin, this->rdbuf()))
__err |= ios_base::failbit;

expect __copy_streambufs return zero on failure, but __copy_streambufs actually
return copied number, and will never be zero if sputc error after have written
some:

bits/streambuf.tcc
 __copy_streambufs_eof(basic_streambuf<_CharT, _Traits>* __sbin,
  basic_streambuf<_CharT, _Traits>* __sbout,
  bool& __ineof)
{
  streamsize __ret = 0;
  __ineof = true;
  typename _Traits::int_type __c = __sbin->sgetc();
  while (!_Traits::eq_int_type(__c, _Traits::eof()))
{
  __c = __sbout->sputc(_Traits::to_char_type(__c));
  if (_Traits::eq_int_type(__c, _Traits::eof()))
{
  __ineof = false;
  break;
}
  ++__ret;
  __c = __sbin->snextc();
}
  return __ret;
}

__copy_streambufs(basic_streambuf<_CharT, _Traits>* __sbin,
  basic_streambuf<_CharT, _Traits>* __sbout)
{
  bool __ineof;
  return __copy_streambufs_eof(__sbin, __sbout, __ineof);
}


only __ineof is false can indicate the failure, but it is ignored by
__copy_streambufs.