]> git.ipfire.org Git - thirdparty/gcc.git/commit
Fix non-standard behaviour of std::istream_iterator
authorredi <redi@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 19 Jun 2019 22:57:10 +0000 (22:57 +0000)
committerredi <redi@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 19 Jun 2019 22:57:10 +0000 (22:57 +0000)
commit4af63f8369114e24f1ddab531f06fb3902a56bf4
treecc296691181aaf4a131f07a799482aba89f10863
parent6c7d761a3f5fd7d19795d1d4b9b027a04b3fe88b
Fix non-standard behaviour of std::istream_iterator

The current implementation of istream_iterator allows the iterator to be
reused after reaching end-of-stream, so that subsequent reads from the
stream can succeed (e.g. if the stream state has been cleared and stream
position changed from EOF). The P0738R2 paper clarified that the
expected behaviour is to set the stream pointer to null after reaching
end-of-stream, preventing further reads.

This implements that requirement, and adds the new default constructor
to std::ostream_iterator.

* include/bits/stream_iterator.h (istream_iterator::_M_equal()): Make
private.
(istream_iterator::_M_read()): Do not check stream state before
attempting extraction. Set stream pointer to null when extraction
fails (P0738R2).
(operator==(const istream_iterator&, const istream_iterator&)): Change
to be a hidden friend of istream_iterator.
(operator!=(const istream_iterator&, const istream_iterator&)):
Likewise.
(ostream_iterator::ostream_iterator()): Add default constructor.
(ostream_iterator::ostream_iterator(ostream_type*, const C*)): Use
addressof.
* testsuite/24_iterators/istream_iterator/1.cc: New test.
* testsuite/24_iterators/ostream_iterator/1.cc: New test.
* testsuite/24_iterators/ostream_iterator/70766.cc: Also check
constructor taking a string.
* testsuite/24_iterators/ostream_iterator/requirements/constexpr.cc:
New test.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@272491 138bc75d-0d04-0410-961f-82ee72b054a4
libstdc++-v3/ChangeLog
libstdc++-v3/include/bits/stream_iterator.h
libstdc++-v3/testsuite/24_iterators/istream_iterator/1.cc [new file with mode: 0644]
libstdc++-v3/testsuite/24_iterators/ostream_iterator/1.cc [new file with mode: 0644]
libstdc++-v3/testsuite/24_iterators/ostream_iterator/70766.cc
libstdc++-v3/testsuite/24_iterators/ostream_iterator/requirements/constexpr.cc [new file with mode: 0644]