http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60959
--- Comment #5 from Jonathan Wakely <redi at gcc dot gnu.org> --- Andrew is correct, the standard says: Requires: s shall not be a null pointer. So your program has undefined behaviour and should be fixed. You can clear the badbit with cout.clear()