https://gcc.gnu.org/bugzilla/show_bug.cgi?id=59568
--- Comment #6 from Jonathan Wakely <redi at gcc dot gnu.org> --- The simplest fix is just: --- a/libstdc++-v3/include/std/complex +++ b/libstdc++-v3/include/std/complex @@ -495,6 +495,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION _Tp __re_x, __im_x; _CharT __ch; __is >> __ch; + if (!__is) + return __is; if (__ch == '(') { __is >> __re_x >> __ch; i.e. don't use putback if we didn't extract a character, so don't clear the eofbit unless there's actually something to putback. But the current implementation has other problems, like not doing a putback for the character extracted when a ',' or ')' is not found. This is closely related to https://wg21.link/lwg2714