r272491 - in /trunk/libstdc++-v3: ChangeLog inc...

redi@gcc.gnu.org redi@gcc.gnu.org
Wed Jun 19 22:57:00 GMT 2019


Author: redi
Date: Wed Jun 19 22:57:10 2019
New Revision: 272491

URL: https://gcc.gnu.org/viewcvs?rev=272491&root=gcc&view=rev
Log:
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.

Added:
    trunk/libstdc++-v3/testsuite/24_iterators/istream_iterator/1.cc
    trunk/libstdc++-v3/testsuite/24_iterators/ostream_iterator/1.cc
      - copied, changed from r272490, trunk/libstdc++-v3/testsuite/24_iterators/ostream_iterator/70766.cc
    trunk/libstdc++-v3/testsuite/24_iterators/ostream_iterator/requirements/constexpr.cc
      - copied, changed from r272490, trunk/libstdc++-v3/testsuite/24_iterators/ostream_iterator/70766.cc
Modified:
    trunk/libstdc++-v3/ChangeLog
    trunk/libstdc++-v3/include/bits/stream_iterator.h
    trunk/libstdc++-v3/testsuite/24_iterators/ostream_iterator/70766.cc



More information about the Libstdc++-cvs mailing list