libstdc++: Fix exception handling in std::ostream seek functions
authorJonathan Wakely <jwakely@redhat.com>
Fri, 25 Jun 2021 17:31:23 +0000 (18:31 +0100)
committerJonathan Wakely <jwakely@redhat.com>
Fri, 25 Jun 2021 17:47:23 +0000 (18:47 +0100)
commit9b6c65c754f2b2a78f5353219ec62817064e0d24
tree761a79c58e3521507d40240ff27043fe1db56718
parent7ab7fa1b51cb7227e051842bcb971b95c962327a
libstdc++: Fix exception handling in std::ostream seek functions

N3168 added the requirement that the [ostream.seeks] functions create a
sentry object. Nothing in the requirements of those functions says
anything about catching exceptions and setting badbit.

As well as not catching exceptions, this change results in another
observable behaviour change. Previously seeking on a stream with eofbit
set would work (as long as badbit and failbit weren't set). The
construction of a sentry causes failbit to be set when eofbit is set,
which causes the seek to fail. It is necessary to clear the eofbit
before seeking now.

libstdc++-v3/ChangeLog:

* include/bits/ostream.tcc (sentry): Only set failbit if badbit
is set, not if eofbit is set.
(tellp, seekp, seekp): Create sentry object. Do not set badbit
on exceptions.
* testsuite/27_io/basic_ostream/seekp/char/exceptions_badbit_throw.cc:
Adjust expected behaviour.
* testsuite/27_io/basic_ostream/seekp/wchar_t/exceptions_badbit_throw.cc:
Likewise.
* testsuite/27_io/basic_ostream/tellp/char/exceptions_badbit_throw.cc:
Likewise.
* testsuite/27_io/basic_ostream/tellp/wchar_t/exceptions_badbit_throw.cc:
Likewise.
* testsuite/27_io/basic_ostream/seekp/char/n3168.cc: New test.
* testsuite/27_io/basic_ostream/seekp/wchar_t/n3168.cc: New test.
* testsuite/27_io/basic_ostream/tellp/char/n3168.cc: New test.
* testsuite/27_io/basic_ostream/tellp/wchar_t/n3168.cc: New test.
libstdc++-v3/include/bits/ostream.tcc
libstdc++-v3/testsuite/27_io/basic_ostream/seekp/char/exceptions_badbit_throw.cc
libstdc++-v3/testsuite/27_io/basic_ostream/seekp/char/n3168.cc [new file with mode: 0644]
libstdc++-v3/testsuite/27_io/basic_ostream/seekp/wchar_t/exceptions_badbit_throw.cc
libstdc++-v3/testsuite/27_io/basic_ostream/seekp/wchar_t/n3168.cc [new file with mode: 0644]
libstdc++-v3/testsuite/27_io/basic_ostream/tellp/char/exceptions_badbit_throw.cc
libstdc++-v3/testsuite/27_io/basic_ostream/tellp/char/n3168.cc [new file with mode: 0644]
libstdc++-v3/testsuite/27_io/basic_ostream/tellp/wchar_t/exceptions_badbit_throw.cc
libstdc++-v3/testsuite/27_io/basic_ostream/tellp/wchar_t/n3168.cc [new file with mode: 0644]