[Bug libstdc++/45628] std::fstream::tellg invalidates I/O buffer
potswa at mac dot com
gcc-bugzilla@gcc.gnu.org
Fri Sep 17 17:52:00 GMT 2010
------- Comment #38 from potswa at mac dot com 2010-09-17 17:51 -------
Created an attachment (id=21822)
--> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=21822&action=view)
Works with codecvt. Tested Tested x86_64-darwin, mainline
Ah, now I see the trick:
if (__off == 0 && !(_M_mode & ios_base::out))
So if the file is open for writing, disable the optimization.
I had a problem with this condition for these testcases:
27_io/basic_filebuf/sputbackc/char/1-io.cc
27_io/basic_filebuf/sputbackc/char/2-io.cc
which contain code such as
strmsz_2 = fb_01.sputn(", i wanna reach out and", 10);
fb_01.pubseekoff(0, std::ios_base::cur); // if this doesn't flush
c1 = fb_01.sgetc(); // this underflow is ignored
c2 = fb_01.sputbackc('z'); // as well as this putback
Essentially, pubseekoff(0,cur) is being used as a sync(). I see nothing in the
Standard to support that, and indeed the sync() shouldn't be needed either, so
I was planning to open a new bug.
Anyway, if I apply your limitation to my patch, it passes the unmodified
testsuite, so here it is.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45628
More information about the Gcc-bugs
mailing list