This page is a snapshot from the LWG issues list, see theLibrary Active Issues List for more information and the meaning ofC++17 status.
basic_filebuf's relation to CFILE semanticsSection: 31.10.3.5[filebuf.virtuals]Status:C++17Submitter: Aaron BallmanOpened: 2015-02-09Last modified: 2017-07-30
Priority:2
View all otherissues in [filebuf.virtuals].
View all issues withC++17 status.
Discussion:
The restrictions on reading and writing a sequence controlled by an object of classbasic_filebuf<charT, traits> are the same as for reading and writing with the Standard C libraryFILEs. One of the restrictions placed by C is on the behavior of a stream that is opened for input and output. See the C99 standard, 7.19.5.3p6 for more details, but the gist is that when opened in update mode, reads and writes must have an intervening file positioning or flushing call to not trigger UB.
31.10.3.5[filebuf.virtuals] p13 specifies thatbasic_filebuf::seekoff() callsstd::fseek(). However, there is no mention ofstd::fseek() inbasic_filebuf::seekpos(), and no mention ofstd::fflush() inbasic_filebuf::sync(), which seem like an oversight.
Previous resolution [SUPERSEDED]:
This wording is relative to N4296.
Change 31.10.3.5[filebuf.virtuals] p16 as follows [Editorial note: A footnote referring to
fseekis not needed,because this is already covered by the existing footnote 334]:-16- Alters the file position, if possible, to correspond to the position stored in
sp(as described below).Altering the file position performs as follows:
if
(om & ios_base::out) != 0, then update the output sequence and write any unshift sequence;set the file position to
spas if by callingstd::fseek(file, sp, SEEK_SET);if
(om & ios_base::in) != 0, then update the input sequence;where
omis the open mode passed to the last call toopen(). The operation fails ifis_open()returns false.Change 31.10.3.5[filebuf.virtuals] p19 as follows and add a new footnote that mimics comparable footnotes in31.10.3.4[filebuf.members] and 31.10.3.5[filebuf.virtuals]:
-19-Effects: If a put area exists, calls
filebuf::overflowto write the characters to the file, thenflushes the file as if by callingstd::fflush(file)[Footnote: The function signaturefflush(FILE*)is declared in<cstdio>(27.9.2).]. If a get area exists, the effect is implementation-defined.
[2015-05, Lenexa]
Aaron provides improved wording by removing the params fromstd::fseek() due to the concernsregarding the parameters on systems wherefseek uses 32-bit parameters.
drops thestd::
drops the footnote forfflush
replacesfseek withfsetpos
Previous resolution [SUPERSEDED]:
This wording is relative to N4431.
Change 31.10.3.5[filebuf.virtuals] p16 as follows [Editorial note: A footnote referring to
fseekis not needed,because this is already covered by the existing footnote 334]:-16- Alters the file position, if possible, to correspond to the position stored in
sp(as described below).Altering the file position performs as follows:
if
(om & ios_base::out) != 0, then update the output sequence and write any unshift sequence;set the file position to
spas if by a call tostd::fseek;if
(om & ios_base::in) != 0, then update the input sequence;where
omis the open mode passed to the last call toopen(). The operation fails ifis_open()returns false.Change 31.10.3.5[filebuf.virtuals] p19 as follows and add a new footnote that mimics comparable footnotes in31.10.3.4[filebuf.members] and 31.10.3.5[filebuf.virtuals]:
-19-Effects: If a put area exists, calls
filebuf::overflowto write the characters to the file, thenflushes the file as if by callingstd::fflush(file)[Footnote: The function signaturefflush(FILE*)is declared in<cstdio>(27.9.2).]. If a get area exists, the effect is implementation-defined.
Proposed resolution:
This wording is relative to N4431.
Change 31.10.3.5[filebuf.virtuals] p16 as follows:
-16- Alters the file position, if possible, to correspond to the position stored in
sp(as described below).Altering the file position performs as follows:
if
(om & ios_base::out) != 0, then update the output sequence and write any unshift sequence;set the file position to
spas if by a call tofsetpos;if
(om & ios_base::in) != 0, then update the input sequence;where
omis the open mode passed to the last call toopen(). The operation fails ifis_open()returns false.
Change 31.10.3.5[filebuf.virtuals] p19 as follows:
-19-Effects: If a put area exists, calls
filebuf::overflowto write the characters to the file, thenflushes the file as if by callingfflush(file). If a get area exists, the effect is implementation-defined.