https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91653
Liu Hao <lh_mouse at 126 dot com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |lh_mouse at 126 dot com --- Comment #5 from Liu Hao <lh_mouse at 126 dot com> --- This may be inconsistency (if not necessarily a defect) in the C++ standard, since both `basic_ostream::{put,write}`, as UnformattedOutputFunctions, set `badbit` in case of output failure, but `operator<<(basic_streambuf*)` doesn't. Nevertheless GCC is doing the right thing and conform to all standards. It should also be noted that if `operator<<(basic_streambuf*)` could not extract any character, `failbit` is set on the output stream. Thus correct use of this function requires a loop, as follows: ``` bool copy_stream(std::ostream& os, std::istream& is) { while(os && (is.rdbuf()->sgetc() != std::istream::traits_type::eof())) os << is.rdbuf(); return !!os; } ``` Anyway, it is not a bug in libstdc++.