https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69218

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |INVALID

--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
This is the correct behaviour required by the C++ standard, your assertion is
incorrect, that is not guaranteed to always be true.

When reading the last word of the file (which in your test is "character") the
compiler keeps reading while there are non-whitespace characters. Because there
are no non-whitespace characters after the word "character" it stops reading
and sets eofbit, but doesn't set failbit because reading succeeded.

If you have a newline at the end then reading the word "character" does not
reach EOF, but on the next time round the loop it fails to read any
non-whitespace characters, so sets failbit.

This is why you should write "while (in >> w)" instead of checking for EOF.

Reply via email to