From e5012ba5ec6637f89f3d100821cc3fe78dfa9994 Mon Sep 17 00:00:00 2001 From: Paolo Carlini Date: Mon, 29 Sep 2003 17:36:18 +0000 Subject: [PATCH] [multiple changes] 2003-09-29 Paolo Carlini PR libstdc++/12296 * include/bits/istream.tcc (peek): Set eofbit if sgetc returns eof. * testsuite/27_io/basic_istream/peek/char/12296.cc: New, from the PR. 2003-09-29 Nathan Myers Paolo Carlini PR libstdc++/11400 * include/bits/stl_algo.h (search_n): Use iterator_traits<>::difference_type for __n. * testsuite/25_algorithms/search_n/11400.cc: New, from the PR. From-SVN: r71911 --- libstdc++-v3/ChangeLog | 16 ++++++++ libstdc++-v3/include/bits/istream.tcc | 6 ++- libstdc++-v3/include/bits/stl_algo.h | 4 +- .../testsuite/25_algorithms/search_n/11400.cc | 32 +++++++++++++++ .../27_io/basic_istream/peek/char/12296.cc | 41 +++++++++++++++++++ 5 files changed, 96 insertions(+), 3 deletions(-) create mode 100644 libstdc++-v3/testsuite/25_algorithms/search_n/11400.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_istream/peek/char/12296.cc diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index d421c40a3b3..08ce582dc9c 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,19 @@ +2003-09-29 Paolo Carlini + + PR libstdc++/12296 + * include/bits/istream.tcc (peek): Set eofbit if sgetc + returns eof. + * testsuite/27_io/basic_istream/peek/char/12296.cc: + New, from the PR. + +2003-09-29 Nathan Myers + Paolo Carlini + + PR libstdc++/11400 + * include/bits/stl_algo.h (search_n): + Use iterator_traits<>::difference_type for __n. + * testsuite/25_algorithms/search_n/11400.cc: New, from the PR. + 2003-09-29 Paolo Carlini * testsuite/22_locale/locale/cons/12352.cc: diff --git a/libstdc++-v3/include/bits/istream.tcc b/libstdc++-v3/include/bits/istream.tcc index e6677c523a4..bf583377e72 100644 --- a/libstdc++-v3/include/bits/istream.tcc +++ b/libstdc++-v3/include/bits/istream.tcc @@ -761,7 +761,11 @@ namespace std if (__cerb) { try - { __c = this->rdbuf()->sgetc(); } + { + __c = this->rdbuf()->sgetc(); + if (traits_type::eq_int_type(__c, traits_type::eof())) + this->setstate(ios_base::eofbit); + } catch(...) { // 27.6.1.3 paragraph 1 diff --git a/libstdc++-v3/include/bits/stl_algo.h b/libstdc++-v3/include/bits/stl_algo.h index 7b3fa9d4232..598eb0f01c9 100644 --- a/libstdc++-v3/include/bits/stl_algo.h +++ b/libstdc++-v3/include/bits/stl_algo.h @@ -609,7 +609,7 @@ namespace std else { __first = std::find(__first, __last, __val); while (__first != __last) { - _Integer __n = __count - 1; + typename iterator_traits<_ForwardIterator>::difference_type __n = __count - 1; _ForwardIterator __i = __first; ++__i; while (__i != __last && __n != 0 && *__i == __val) { @@ -661,7 +661,7 @@ namespace std ++__first; } while (__first != __last) { - _Integer __n = __count - 1; + typename iterator_traits<_ForwardIterator>::difference_type __n = __count - 1; _ForwardIterator __i = __first; ++__i; while (__i != __last && __n != 0 && __binary_pred(*__i, __val)) { diff --git a/libstdc++-v3/testsuite/25_algorithms/search_n/11400.cc b/libstdc++-v3/testsuite/25_algorithms/search_n/11400.cc new file mode 100644 index 00000000000..a7003768ee2 --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/search_n/11400.cc @@ -0,0 +1,32 @@ +// Copyright (C) 2003 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 2, 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 COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// 25.1.9 [lib.alg.search] + +// { dg-do compile } + +#include +#include + +struct Integral { operator int() const; }; + +namespace std +{ + template int* search_n (int*, int*, Integral, const int&); + template int* search_n (int*, int*, Integral, const int&, greater); +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/peek/char/12296.cc b/libstdc++-v3/testsuite/27_io/basic_istream/peek/char/12296.cc new file mode 100644 index 00000000000..8b4ef74e423 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/peek/char/12296.cc @@ -0,0 +1,41 @@ +// Copyright (C) 2003 Free Software Foundation +// +// 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 2, 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 COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// 27.6.1.3 unformatted input functions + +#include +#include + +// libstdc++/12296 +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + istringstream stream; + VERIFY( stream.rdstate() == ios_base::goodbit ); + istringstream::int_type c = stream.peek(); + VERIFY( c == istringstream::traits_type::eof() ); + VERIFY( stream.rdstate() == ios_base::eofbit ); +} + +int main() +{ + test01(); + return 0; +} -- 2.30.2