This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
[PATCH] istream_iterator: test for read in ctor
- From: Petr Ovtchenkov <ptr at void-ptr dot info>
- To: libstdc++ at gcc dot gnu dot org
- Date: Mon, 28 Aug 2017 11:50:45 +0300
- Subject: [PATCH] istream_iterator: test for read in ctor
- Authentication-results: sourceware.org; auth=none
Standard say:
27.6.1 Class template istream_iterator [istream.iterator]
1 The class template istream_iterator is an input iterator (27.2.3)
that reads (using operator>>) successive elements from the input
stream for which it was constructed.
-> After it is constructed, and every time ++ is used, the iterator
-> reads and stores a value of T.
...
27.6.1.1 istream_iterator constructors and destructor [istream.iterator.cons]
...
istream_iterator(istream_type& s);
-> 3 Effects: Initializes in_stream with addressof(s). value may be initialized
-> during construction or the first time it is referenced.
4 Postconditions: in_stream == addressof(s).
Current position is "After it is constructed ... the iterator reads and stores
a value of T.".
---
.../24_iterators/istream_iterator/81964.cc | 63 ++++++++++++++++++++++
1 file changed, 63 insertions(+)
create mode 100644 libstdc++-v3/testsuite/24_iterators/istream_iterator/81964.cc
diff --git a/libstdc++-v3/testsuite/24_iterators/istream_iterator/81964.cc b/libstdc++-v3/testsuite/24_iterators/istream_iterator/81964.cc
new file mode 100644
index 0000000..f2df7e3
--- /dev/null
+++ b/libstdc++-v3/testsuite/24_iterators/istream_iterator/81964.cc
@@ -0,0 +1,63 @@
+// { dg-options "-std=gnu++11" }
+
+// Copyright (C) 2017 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+#include <sstream>
+#include <iterator>
+#include <testsuite_hooks.h>
+
+// libstdc++/81964
+void test0x()
+{
+ using namespace std;
+ bool test __attribute__((unused)) = true;
+
+ /*
+ 27.6.1 Class template istream_iterator [istream.iterator]
+
+ 1 The class template istream_iterator is an input iterator (27.2.3)
+ that reads (using operator>>) successive elements from the input
+ stream for which it was constructed.
+ -> After it is constructed, and every time ++ is used, the iterator
+ -> reads and stores a value of T.
+ ...
+
+ 27.6.1.1 istream_iterator constructors and destructor [istream.iterator.cons]
+ ...
+ istream_iterator(istream_type& s);
+ -> 3 Effects: Initializes in_stream with addressof(s). value may be initialized
+ -> during construction or the first time it is referenced.
+ 4 Postconditions: in_stream == addressof(s).
+
+ Current position is "After it is constructed ... the iterator reads and stores
+ a value of T.".
+ */
+
+ std::istringstream s("1 2");
+ std::istream_iterator<int> ii1(s); // read 1
+ std::istream_iterator<int> ii2(s); // read 2
+
+ VERIFY( *ii2 == 2 );
+ VERIFY( *ii1 == 1 );
+}
+
+int main()
+{
+ test0x();
+ return 0;
+}
--
2.10.1