This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[v3] istream::ignore issues
- From: Benjamin Kosnik <bkoz at redhat dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Thu, 8 Aug 2002 23:02:07 -0700
- Subject: [v3] istream::ignore issues
As reported by Danny Smith. The fix was a bit off, and broke
test09. This fixes the reported problem (now test10) without causing
new breakage.
tested x86/linux + interactive tests in 27_io/narrow_stream_objects.cc
gcc
quequed for gcc-3.2.1
2002-08-08 Danny Smith <dannysmith@users.sourceforge.net>
Benjamin Kosnik <bkoz@redhat.com>
* include/bits/istream.tcc (basic_istream::ignore): Use sbumpc,
not snextc.
* testsuite/27_io/narrow_stream_objects.cc (test10): Add.
Index: include/bits/istream.tcc
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/include/bits/istream.tcc,v
retrieving revision 1.33
diff -c -p -r1.33 istream.tcc
*** include/bits/istream.tcc 31 Jul 2002 02:47:33 -0000 1.33
--- include/bits/istream.tcc 9 Aug 2002 05:56:54 -0000
*************** namespace std
*** 722,744 ****
{
const int_type __eof = traits_type::eof();
__streambuf_type* __sb = this->rdbuf();
! int_type __c = __sb->sgetc();
__n = min(__n, numeric_limits<streamsize>::max());
while (_M_gcount < __n
! && !traits_type::eq_int_type(__c, __eof)
! && !traits_type::eq_int_type(__c, __delim))
{
- __c = __sb->snextc();
++_M_gcount;
}
if (traits_type::eq_int_type(__c, __eof))
this->setstate(ios_base::eofbit);
- else if (traits_type::eq_int_type(__c, __delim))
- {
- __sb->sbumpc();
- ++_M_gcount;
- }
}
catch(exception& __fail)
{
--- 722,739 ----
{
const int_type __eof = traits_type::eof();
__streambuf_type* __sb = this->rdbuf();
! int_type __c;
__n = min(__n, numeric_limits<streamsize>::max());
while (_M_gcount < __n
! && !traits_type::eq_int_type(__c = __sb->sbumpc(), __eof))
{
++_M_gcount;
+ if (traits_type::eq_int_type(__c, __delim))
+ break;
}
if (traits_type::eq_int_type(__c, __eof))
this->setstate(ios_base::eofbit);
}
catch(exception& __fail)
{
Index: testsuite/27_io/narrow_stream_objects.cc
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/testsuite/27_io/narrow_stream_objects.cc,v
retrieving revision 1.10
diff -c -p -r1.10 narrow_stream_objects.cc
*** testsuite/27_io/narrow_stream_objects.cc 15 May 2002 10:27:29 -0000 1.10
--- testsuite/27_io/narrow_stream_objects.cc 9 Aug 2002 05:56:55 -0000
***************
*** 66,72 ****
#include <cstdlib>
#include <cstring>
#include <ctime>
! #include <testsuite_hooks.h>
// Include iostream last, just to make is as difficult as possible to
// properly initialize the standard iostream objects.
--- 66,73 ----
#include <cstdlib>
#include <cstring>
#include <ctime>
! //#include <testsuite_hooks.h>
! #define VERIFY(x) x
// Include iostream last, just to make is as difficult as possible to
// properly initialize the standard iostream objects.
*************** void test03()
*** 116,134 ****
// Interactive test, to be exercised as follows:
// assign stderr to stdout in shell command line,
// pipe stdout to cat process and/or redirect stdout to file.
! // "hello fine world\n" should be written to stdout in proper order.
! // This is a version of the scott snyder test taken from:
! // http://gcc.gnu.org/ml/libstdc++/1999-q4/msg00108.html
void test04()
{
using namespace std;
cout << "hello ";
! cout.flush ();
cerr << "fine ";
! cerr.flush ();
cout << "world" << endl;
! cout.flush ();
}
// Interactive test, to be exercised as follows:
--- 117,136 ----
// Interactive test, to be exercised as follows:
// assign stderr to stdout in shell command line,
// pipe stdout to cat process and/or redirect stdout to file.
! // a.out >& output
! // "hello fine world\n" should be written to stdout, and output, in
! // proper order. This is a version of the scott snyder test taken
! // from: http://gcc.gnu.org/ml/libstdc++/1999-q4/msg00108.html
void test04()
{
using namespace std;
cout << "hello ";
! cout.flush();
cerr << "fine ";
! cerr.flush();
cout << "world" << endl;
! cout.flush();
}
// Interactive test, to be exercised as follows:
*************** void test04()
*** 138,144 ****
// depending upon buffering mode enforced.
void test05()
{
! std::cout << "hello" << ' ' << "world" <<std::endl;
std::cout << "Enter your name: ";
std::string s;
std::cin >> s;
--- 140,146 ----
// depending upon buffering mode enforced.
void test05()
{
! std::cout << "hello" << ' ' << "world" << std::endl;
std::cout << "Enter your name: ";
std::string s;
std::cin >> s;
*************** void test06()
*** 169,175 ****
void test07()
{
bool test = true;
! std::cout << "Please, enter 'test':";
std::string s;
std::getline(std::cin, s, '\n');
VERIFY( s == "test" );
--- 171,177 ----
void test07()
{
bool test = true;
! std::cout << "Enter 'test':";
std::string s;
std::getline(std::cin, s, '\n');
VERIFY( s == "test" );
*************** void test08()
*** 188,197 ****
void test09()
{
bool test = true;
! std::cout << "Enter name: ";
std::cin.ignore(2048, '\n');
}
int
main()
{
--- 190,210 ----
void test09()
{
bool test = true;
! std::cout << "Enter favorite beach: ";
std::cin.ignore(2048, '\n');
}
+ // http://gcc.gnu.org/ml/libstdc++/2002-08/msg00060.html
+ // Should only have to hit enter once.
+ void
+ test10()
+ {
+ using namespace std;
+ cout << "Press ENTER once\n";
+ cin.ignore(1);
+ cout << "_M_gcount: "<< cin.gcount() << endl;
+ }
+
int
main()
{
*************** main()
*** 205,209 ****
--- 218,223 ----
// test07();
// test08();
// test09();
+ // test10();
return 0;
}