https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106248
--- Comment #6 from Jonathan Wakely <redi at gcc dot gnu.org> --- I think this would restore the previous behaviour without losing the overflow prevention: --- a/libstdc++-v3/include/std/istream +++ b/libstdc++-v3/include/std/istream @@ -813,8 +813,17 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION else { if (__n == (size_t)-1) - __n = __gnu_cxx::__numeric_traits<streamsize>::__max; - std::__istream_extract(__in, __s, __n / sizeof(_CharT)); + { + __n = __gnu_cxx::__numeric_traits<streamsize>::__max; + std::__istream_extract(__in, __s, __n / sizeof(_CharT)); + } + else + { + std::__istream_extract(__in, __s, __n / sizeof(_CharT)); + if (__in.good() && _Traits::eq_int_type(__in.rdbuf()->snextc(), + _Traits::eof())) + __in.setstate(ios_base::eofbit); + } } return __in; }