https://gcc.gnu.org/bugzilla/show_bug.cgi?id=28103
--- Comment #7 from Jonathan Wakely <redi at gcc dot gnu.org> --- I think we can just do this in __ostream_insert: --- a/libstdc++-v3/include/bits/ostream_insert.h +++ b/libstdc++-v3/include/bits/ostream_insert.h @@ -103,6 +103,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION else __ostream_write(__out, __s, __n); __out.width(0); + + if (__builtin_expect(__out.bad(), 0)) + __out.setstate(__ios_base::failbit); } __catch(__cxxabiv1::__forced_unwind&) { If __ostream_write or __ostream_fill fails to insert something (as unformatted output functions) they'll set badbit. So we can check for that and set failbit explicitly, to meet the requirement for a formatted output function.