From 2fd819efe5eef2c17be4555fe3d9889938d3c68c Mon Sep 17 00:00:00 2001 From: Benjamin Kosnik Date: Fri, 3 May 2002 18:22:58 +0000 Subject: [PATCH] re PR libstdc++/6549 (std::getline(std::cin,s) work wrong at FreeBSD 4.5) 2002-05-03 Benjamin Kosnik PR libstdc++/6549. * include/bits/fstream.tcc (filebuf::_M_underflow_common): Revert. * testsuite/27_io/narrow_stream_objects.cc (test07): Add. From-SVN: r53107 --- libstdc++-v3/ChangeLog | 6 +++++ libstdc++-v3/include/bits/fstream.tcc | 23 +++++++------------ .../testsuite/27_io/narrow_stream_objects.cc | 11 +++++++++ 3 files changed, 25 insertions(+), 15 deletions(-) diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index b3da14efe86..cb6dfa94eba 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,9 @@ +2002-05-03 Benjamin Kosnik + + PR libstdc++/6549. + * include/bits/fstream.tcc (filebuf::_M_underflow_common): Revert. + * testsuite/27_io/narrow_stream_objects.cc (test07): Add. + 2002-05-03 Kaveh R. Ghazi * config/os/irix/irix5.2/bits/ctype_noninline.h (classic_table): diff --git a/libstdc++-v3/include/bits/fstream.tcc b/libstdc++-v3/include/bits/fstream.tcc index 40b9f32532d..90850f54f0d 100644 --- a/libstdc++-v3/include/bits/fstream.tcc +++ b/libstdc++-v3/include/bits/fstream.tcc @@ -182,21 +182,6 @@ namespace std return traits_type::to_int_type(*_M_in_cur); } - // Check for unbuffered stream. - if (_M_buf_size == 1) - { - int_type __c = _M_file.sys_getc(); - if (__c != __ret) - { - __ret = __c; - *_M_in_cur = traits_type::to_char_type(__c); - _M_set_determinate(1); - if (__testout) - _M_out_cur = _M_in_cur; - } - return __ret; - } - // Sync internal and external buffers. // NB: __testget -> __testput as _M_buf_unified here. bool __testget = _M_in_cur && _M_in_beg < _M_in_cur; @@ -251,6 +236,14 @@ namespace std __ret = traits_type::to_int_type(*_M_in_cur); if (__bump) _M_in_cur_move(1); + else if (_M_buf_size == 1) + { + // If we are synced with stdio, we have to unget the + // character we just read so that the file pointer + // doesn't move. + _M_file.sys_ungetc(*_M_in_cur); + _M_set_indeterminate(); + } } } } diff --git a/libstdc++-v3/testsuite/27_io/narrow_stream_objects.cc b/libstdc++-v3/testsuite/27_io/narrow_stream_objects.cc index 27291be00fc..016a982c8ef 100644 --- a/libstdc++-v3/testsuite/27_io/narrow_stream_objects.cc +++ b/libstdc++-v3/testsuite/27_io/narrow_stream_objects.cc @@ -165,6 +165,16 @@ void test06() cerr << "i == " << i << endl; } +// libstdc++/6548 +void test07() +{ + bool test = true; + std::cout << "Please, enter 'test':"; + std::string s; + std::getline(std::cin, s, '\n'); + VERIFY( s == "test" ); +} + int main() { @@ -175,5 +185,6 @@ main() // test04(); // test05(); // test06(); + // test07(); return 0; } -- 2.30.2