Skip to content

Instantly share code, notes, and snippets.

@martyngigg
Created December 8, 2021 20:15
Show Gist options
  • Save martyngigg/2f47c7b5ca398d83aa907feb9a179714 to your computer and use it in GitHub Desktop.
Save martyngigg/2f47c7b5ca398d83aa907feb9a179714 to your computer and use it in GitHub Desktop.
EOF bug in libc++
#include <iostream>
#include <sstream>
int main() {
std::stringstream s;
s.exceptions(std::istream::eofbit);
s << "a";
std::cout << "EOF? " << (s.eof() ? "T" : "F") << std::endl;
std::cout << "get: " << s.get() << std::endl;
std::cout << "EOF? " << (s.eof() ? "T" : "F") << std::endl;
std::cout << "get: " << s.get() << std::endl; // throws eoftbit=T
std::cout << "This line should not be reached!\n";
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment