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

--- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> ---
But there is an open FILE and it might have pending writes or ungetc'd data
that should be flushed. I think that's why it's there. Consider:

  FILE* f = std::fopen("81751.txt", "w+");
  std::fwrite("Some words.", 1, 10, f);
  __gnu_cxx::stdio_filebuf<char> buf(f, std::ios::in|std::ios::out, BUFSIZ);
  int c = buf.sgetc();

If the constructor doesn't flush then the read performed by sgetc will follow
the write without an intervening seek or flush, which is undefined behaviour.

The constructor taking a file descriptor creates a new FILE using fdopen, so
there are no buffered writes on the stream, and a flush isn't needed.

Reply via email to