diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index f2936ed29ef..8a781252014 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,30 @@ +2003-12-05 Benjamin Kosnik + + PR libstdc++/13189 + * include/ext/enc_filebuf.h: Fix. + * include/bits/fstream.tcc: Tweak formatting. + * include/bits/postypes.h: Same. + * include/bits/sstream.tcc: Same. + * include/bits/streambuf.tcc: Same. + * testsuite/ext/stdio_filebuf.cc: Split. + * testsuite/ext/stdio_filebuf_2.cc: Split. + * testsuite/ext/stdio_sync_filebuf_char.cc: Split. + * testsuite/ext/stdio_sync_filebuf_wchar_t.cc: Split. + * testsuite/ext/enc_filebuf/char/13189.cc: New. + * testsuite/ext/enc_filebuf/wchar_t/13189.cc: New. + * testsuite/ext/stdio_filebuf/char/1.cc: New. + * testsuite/ext/stdio_filebuf/char/2.cc: New. + * testsuite/ext/stdio_sync_filebuf/char/1.cc: New. + * testsuite/ext/stdio_sync_filebuf/char/12048-1.cc: New. + * testsuite/ext/stdio_sync_filebuf/char/12048-2.cc: New. + * testsuite/ext/stdio_sync_filebuf/char/12048-3.cc: New. + * testsuite/ext/stdio_sync_filebuf/char/12048-4.cc: New. + * testsuite/ext/stdio_sync_filebuf/wchar_t/1.cc: New. + * testsuite/ext/stdio_sync_filebuf/wchar_t/12948-1.cc: New. + * testsuite/ext/stdio_sync_filebuf/wchar_t/12948-2.cc: New. + * testsuite/ext/stdio_sync_filebuf/wchar_t/12948-3.cc: New. + * testsuite/ext/stdio_sync_filebuf/wchar_t/12948-4.cc: New. + 2003-12-05 Carlo Wood PR libstdc++/13045 diff --git a/libstdc++-v3/include/bits/fstream.tcc b/libstdc++-v3/include/bits/fstream.tcc index ef4260b5f81..595d8bde118 100644 --- a/libstdc++-v3/include/bits/fstream.tcc +++ b/libstdc++-v3/include/bits/fstream.tcc @@ -161,7 +161,6 @@ namespace std { streamsize __ret = -1; const bool __testin = this->_M_mode & ios_base::in; - if (__testin && this->is_open()) { // For a stateful encoding (-1) the pending sequence might be just @@ -170,7 +169,6 @@ namespace std if (__check_facet(_M_codecvt).encoding() >= 0) __ret += _M_file.showmanyc() / _M_codecvt->max_length(); } - return __ret; } @@ -182,7 +180,6 @@ namespace std int_type __ret = traits_type::eof(); const bool __testin = this->_M_mode & ios_base::in; const bool __testout = this->_M_mode & ios_base::out; - if (__testin && !_M_writing) { // Check for pback madness, and if so swich back to the @@ -323,14 +320,12 @@ namespace std { int_type __ret = traits_type::eof(); const bool __testin = this->_M_mode & ios_base::in; - if (__testin && !_M_writing) { // Remember whether the pback buffer is active, otherwise below // we may try to store in it a second char (libstdc++/9761). const bool __testpb = this->_M_pback_init; const bool __testeof = traits_type::eq_int_type(__i, __ret); - int_type __tmp; if (this->eback() < this->gptr()) { @@ -378,7 +373,6 @@ namespace std int_type __ret = traits_type::eof(); const bool __testeof = traits_type::eq_int_type(__c, __ret); const bool __testout = this->_M_mode & ios_base::out; - if (__testout && !_M_reading) { if (this->pbase() < this->pptr()) @@ -391,7 +385,7 @@ namespace std } // Convert pending sequence to external representation, - // output. + // and output. if (_M_convert_to_external(this->pbase(), this->pptr() - this->pbase()) && (!__testeof || (__testeof && !_M_file.sync()))) @@ -436,7 +430,6 @@ namespace std // Sizes of external and pending output. streamsize __elen = 0; streamsize __plen = 0; - if (__check_facet(_M_codecvt).always_noconv()) { __elen += _M_file.xsputn(reinterpret_cast(__ibuf), __ilen); @@ -499,11 +492,10 @@ namespace std basic_filebuf<_CharT, _Traits>:: xsputn(const _CharT* __s, streamsize __n) { - streamsize __ret = 0; - // Optimization in the always_noconv() case, to be generalized in the // future: when __n is sufficiently large we write directly instead of // using the buffer. + streamsize __ret = 0; const bool __testout = this->_M_mode & ios_base::out; if (__testout && !_M_reading && __check_facet(_M_codecvt).always_noconv()) @@ -538,8 +530,7 @@ namespace std __ret = __streambuf_type::xsputn(__s, __n); } else - __ret = __streambuf_type::xsputn(__s, __n); - + __ret = __streambuf_type::xsputn(__s, __n); return __ret; } @@ -575,14 +566,13 @@ namespace std basic_filebuf<_CharT, _Traits>:: seekoff(off_type __off, ios_base::seekdir __way, ios_base::openmode) { - pos_type __ret = pos_type(off_type(-1)); - int __width = 0; if (_M_codecvt) __width = _M_codecvt->encoding(); if (__width < 0) __width = 0; + pos_type __ret = pos_type(off_type(-1)); const bool __testfail = __off != 0 && __width <= 0; if (this->is_open() && !__testfail) { @@ -630,12 +620,10 @@ namespace std seekpos(pos_type __pos, ios_base::openmode) { pos_type __ret = pos_type(off_type(-1)); - if (this->is_open()) { // Ditch any pback buffers to avoid confusion. _M_destroy_pback(); - __ret = _M_seek(off_type(__pos), ios_base::beg, __pos.state()); } return __ret; @@ -650,8 +638,7 @@ namespace std if (_M_terminate_output()) { // Returns pos_type(off_type(-1)) in case of failure. - __ret = pos_type(_M_file.seekoff(__off, __way)); - + __ret = pos_type(_M_file.seekoff(__off, __way)); _M_reading = false; _M_writing = false; _M_ext_next = _M_ext_end = _M_ext_buf; @@ -667,9 +654,8 @@ namespace std basic_filebuf<_CharT, _Traits>:: _M_terminate_output() { - bool __testvalid = true; - // Part one: update the output sequence. + bool __testvalid = true; if (this->pbase() < this->pptr()) { const int_type __tmp = this->overflow(); @@ -685,7 +671,6 @@ namespace std // get the length of the unshift sequence from codecvt, // without calling unshift. const size_t __blen = 128; - char __buf[__blen]; codecvt_base::result __r; streamsize __ilen = 0; @@ -700,8 +685,7 @@ namespace std else if (__r == codecvt_base::ok || __r == codecvt_base::partial) { - __ilen = __next - __buf; - + __ilen = __next - __buf; if (__ilen > 0) { const streamsize __elen = _M_file.xsputn(__buf, __ilen); @@ -731,18 +715,16 @@ namespace std basic_filebuf<_CharT, _Traits>:: sync() { - int __ret = 0; - // Make sure that the internal buffer resyncs its idea of // the file position with the external file. // NB: _M_file.sync() will be called within. + int __ret = 0; if (this->pbase() < this->pptr()) { const int_type __tmp = this->overflow(); if (traits_type::eq_int_type(__tmp, traits_type::eof())) __ret = -1; - } - + } return __ret; } @@ -752,7 +734,6 @@ namespace std imbue(const locale& __loc) { bool __testfail = false; - if (this->is_open()) { const pos_type __ret = this->seekoff(0, ios_base::cur, diff --git a/libstdc++-v3/include/bits/postypes.h b/libstdc++-v3/include/bits/postypes.h index 935ba7c66f7..c9b46b1d171 100644 --- a/libstdc++-v3/include/bits/postypes.h +++ b/libstdc++-v3/include/bits/postypes.h @@ -146,8 +146,8 @@ namespace std private: friend class streamoff; - __streamoff_base_type _M_off; - _StateT _M_state; + __streamoff_base_type _M_off; + _StateT _M_state; public: // The standard doesn't require that fpos objects can be default diff --git a/libstdc++-v3/include/bits/sstream.tcc b/libstdc++-v3/include/bits/sstream.tcc index dfa1d6810bd..07e13926ba9 100644 --- a/libstdc++-v3/include/bits/sstream.tcc +++ b/libstdc++-v3/include/bits/sstream.tcc @@ -79,8 +79,7 @@ namespace std if (__builtin_expect(!__testout, false)) return traits_type::eof(); - const bool __testeof = traits_type::eq_int_type(__c, - traits_type::eof()); + const bool __testeof = traits_type::eq_int_type(__c, traits_type::eof()); if (__builtin_expect(__testeof, false)) return traits_type::not_eof(__c); @@ -106,8 +105,7 @@ namespace std __tmp.assign(_M_string.data(), this->epptr() - this->pbase()); _M_string.swap(__tmp); _M_sync(const_cast(_M_string.data()), - this->gptr() - this->eback(), - this->pptr() - this->pbase()); + this->gptr() - this->eback(), this->pptr() - this->pbase()); } return this->sputc(traits_type::to_char_type(__c)); } @@ -123,7 +121,6 @@ namespace std { // Update egptr() to match the actual string end. _M_update_egptr(); - if (this->gptr() < this->egptr()) __ret = traits_type::to_int_type(*this->gptr()); } @@ -181,8 +178,7 @@ namespace std basic_stringbuf<_CharT, _Traits, _Alloc>:: seekpos(pos_type __sp, ios_base::openmode __mode) { - pos_type __ret = pos_type(off_type(-1)); - + pos_type __ret = pos_type(off_type(-1)); if (_M_string.capacity()) { off_type __pos (__sp); diff --git a/libstdc++-v3/include/bits/streambuf.tcc b/libstdc++-v3/include/bits/streambuf.tcc index 494b9f0056d..4cc9bf1590a 100644 --- a/libstdc++-v3/include/bits/streambuf.tcc +++ b/libstdc++-v3/include/bits/streambuf.tcc @@ -149,15 +149,13 @@ namespace std extern template class basic_streambuf; extern template streamsize - __copy_streambufs(basic_streambuf*, - basic_streambuf*); + __copy_streambufs(basic_streambuf*, basic_streambuf*); #ifdef _GLIBCXX_USE_WCHAR_T extern template class basic_streambuf; extern template streamsize - __copy_streambufs(basic_streambuf*, - basic_streambuf*); + __copy_streambufs(basic_streambuf*, basic_streambuf*); #endif #endif } // namespace std diff --git a/libstdc++-v3/include/ext/enc_filebuf.h b/libstdc++-v3/include/ext/enc_filebuf.h index a2b3d670570..81dad12f2f9 100644 --- a/libstdc++-v3/include/ext/enc_filebuf.h +++ b/libstdc++-v3/include/ext/enc_filebuf.h @@ -1,6 +1,6 @@ -// __enc_traits layer for filebuf -*- C++ -*- +// filebuf with __enc_traits state type -*- C++ -*- -// Copyright (C) 2002 Free Software Foundation, Inc. +// Copyright (C) 2002, 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 @@ -32,12 +32,14 @@ namespace __gnu_cxx { - // Custom traits type with __enc_traits for state type, all other bits - // equivalent to the required char_traits instantiations. + // Custom traits type with __enc_traits for the state type, and the + // associated fpos<__enc_traits> for the position type, all other + // bits equivalent to the required char_traits instantiations. template struct enc_char_traits: public std::char_traits<_CharT> { - typedef std::__enc_traits state_type; + typedef std::__enc_traits state_type; + typedef typename std::fpos pos_type; }; template @@ -45,17 +47,19 @@ namespace __gnu_cxx : public std::basic_filebuf<_CharT, enc_char_traits<_CharT> > { public: - typedef typename enc_char_traits<_CharT>::state_type state_type; + typedef enc_char_traits<_CharT> traits_type; + typedef typename traits_type::state_type state_type; + typedef typename traits_type::pos_type pos_type; enc_filebuf(state_type& __state) : std::basic_filebuf<_CharT, enc_char_traits<_CharT> >() { // Set state type to something useful. // Something more than copyconstructible is needed here, so - // require copyconstructible + assignment operator. + // require default and copy constructible + assignment operator. __glibcxx_class_requires(state_type, _SGIAssignableConcept); - _M_state_cur = __state; - _M_state_cur._M_init(); + this->_M_state_beg = __state; + this->_M_state_beg._M_init(); }; }; } // namespace __gnu_cxx diff --git a/libstdc++-v3/testsuite/ext/enc_filebuf/char/13189.cc b/libstdc++-v3/testsuite/ext/enc_filebuf/char/13189.cc new file mode 100644 index 00000000000..57c0871ed12 --- /dev/null +++ b/libstdc++-v3/testsuite/ext/enc_filebuf/char/13189.cc @@ -0,0 +1,50 @@ +// 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. + +#include +#include + +int main() +{ + using namespace std; + + typedef __enc_traits state_type; + typedef char char_type; + typedef __gnu_cxx::enc_filebuf filebuf_type; + typedef codecvt enc_codecvt; + + bool test __attribute__((unused)) = true; + ios_base::openmode mode = ios_base::in | ios_base::out | ios_base::trunc; + try + { + state_type st; + filebuf_type fbuf(st); + locale loc(locale::classic(), new enc_codecvt); + fbuf.pubimbue(loc); + fbuf.open("tmp_13189c", mode); + fbuf.sputc('a'); + fbuf.pubseekoff(0, ios_base::beg); + fbuf.sgetc(); + fbuf.close(); + } + catch(...) + { + VERIFY( false ); + } + return 0; +} diff --git a/libstdc++-v3/testsuite/ext/enc_filebuf/wchar_t/13189.cc b/libstdc++-v3/testsuite/ext/enc_filebuf/wchar_t/13189.cc new file mode 100644 index 00000000000..7089b67da33 --- /dev/null +++ b/libstdc++-v3/testsuite/ext/enc_filebuf/wchar_t/13189.cc @@ -0,0 +1,50 @@ +// 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. + +#include +#include + +int main() +{ + using namespace std; + + typedef __enc_traits state_type; + typedef wchar_t char_type; + typedef __gnu_cxx::enc_filebuf filebuf_type; + typedef codecvt enc_codecvt; + + bool test __attribute__((unused)) = true; + ios_base::openmode mode = ios_base::in | ios_base::out | ios_base::trunc; + try + { + state_type st; + filebuf_type fbuf(st); + locale loc(locale::classic(), new enc_codecvt); + fbuf.pubimbue(loc); + fbuf.open("tmp_13189w", mode); + fbuf.sputc(L'a'); + fbuf.pubseekoff(0, ios_base::beg); + fbuf.sgetc(); + fbuf.close(); + } + catch(...) + { + VERIFY( false ); + } + return 0; +} diff --git a/libstdc++-v3/testsuite/ext/stdio_filebuf.cc b/libstdc++-v3/testsuite/ext/stdio_filebuf/char/1.cc similarity index 100% rename from libstdc++-v3/testsuite/ext/stdio_filebuf.cc rename to libstdc++-v3/testsuite/ext/stdio_filebuf/char/1.cc diff --git a/libstdc++-v3/testsuite/ext/stdio_filebuf_2.cc b/libstdc++-v3/testsuite/ext/stdio_filebuf/char/2.cc similarity index 100% rename from libstdc++-v3/testsuite/ext/stdio_filebuf_2.cc rename to libstdc++-v3/testsuite/ext/stdio_filebuf/char/2.cc diff --git a/libstdc++-v3/testsuite/ext/stdio_sync_filebuf_char.cc b/libstdc++-v3/testsuite/ext/stdio_sync_filebuf/char/1.cc similarity index 52% rename from libstdc++-v3/testsuite/ext/stdio_sync_filebuf_char.cc rename to libstdc++-v3/testsuite/ext/stdio_sync_filebuf/char/1.cc index 5134cadfbe9..c57186d52b3 100644 --- a/libstdc++-v3/testsuite/ext/stdio_sync_filebuf_char.cc +++ b/libstdc++-v3/testsuite/ext/stdio_sync_filebuf/char/1.cc @@ -56,85 +56,8 @@ void test01() fclose(fin); } -// libstdc++/12048 -void test02() -{ - bool test __attribute__((unused)) = true; - const char* name = "cin_unget-1.txt"; - - std::FILE* file = std::fopen(name, "r"); - __gnu_cxx::stdio_sync_filebuf sbuf(file); - int c1 = sbuf.sbumpc(); - VERIFY( c1 != EOF ); - int c2 = sbuf.sungetc(); - VERIFY( c2 != EOF ); - int c3 = sbuf.sbumpc(); - VERIFY( c3 == c1 ); - - std::fclose(file); -} - -// libstdc++/12048 -void test03() -{ - bool test __attribute__((unused)) = true; - const char* name = "cin_unget-1.txt"; - - std::FILE* file = std::fopen(name, "r"); - __gnu_cxx::stdio_sync_filebuf sbuf(file); - int c1 = sbuf.sbumpc(); - VERIFY( c1 != EOF ); - int c2 = sbuf.sungetc(); - VERIFY( c2 != EOF ); - int c3 = std::fgetc(file); - VERIFY( c3 == c1 ); - - std::fclose(file); -} - -// libstdc++/12048 -void test04() -{ - bool test __attribute__((unused)) = true; - const char* name = "cin_unget-1.txt"; - - std::FILE* file = std::fopen(name, "r"); - __gnu_cxx::stdio_sync_filebuf sbuf(file); - char buf[2]; - VERIFY( sbuf.sgetn(buf, 2) == 2 ); - int c2 = sbuf.sungetc(); - VERIFY( c2 != EOF ); - int c3 = sbuf.sbumpc(); - VERIFY( c3 == std::char_traits::to_int_type(buf[1]) ); - - std::fclose(file); -} - -// libstdc++/12048 -void test05() -{ - bool test __attribute__((unused)) = true; - const char* name = "cin_unget-1.txt"; - - std::FILE* file = std::fopen(name, "r"); - __gnu_cxx::stdio_sync_filebuf sbuf(file); - char buf[2]; - VERIFY( sbuf.sgetn(buf, 2) == 2 ); - int c2 = sbuf.sungetc(); - VERIFY( c2 != EOF ); - int c3 = std::fgetc(file); - VERIFY( c3 == std::char_traits::to_int_type(buf[1]) ); - - std::fclose(file); -} - int main () { test01(); - test02(); - test03(); - test04(); - test05(); - return 0; } diff --git a/libstdc++-v3/testsuite/ext/stdio_sync_filebuf/char/12048-1.cc b/libstdc++-v3/testsuite/ext/stdio_sync_filebuf/char/12048-1.cc new file mode 100644 index 00000000000..e35897e20f1 --- /dev/null +++ b/libstdc++-v3/testsuite/ext/stdio_sync_filebuf/char/12048-1.cc @@ -0,0 +1,46 @@ +// 2003-05-01 Petur Runolfsson + +// 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. + +#include +#include + +// libstdc++/12048 +void test02() +{ + bool test __attribute__((unused)) = true; + const char* name = "cin_unget-1.txt"; + + std::FILE* file = std::fopen(name, "r"); + __gnu_cxx::stdio_sync_filebuf sbuf(file); + int c1 = sbuf.sbumpc(); + VERIFY( c1 != EOF ); + int c2 = sbuf.sungetc(); + VERIFY( c2 != EOF ); + int c3 = sbuf.sbumpc(); + VERIFY( c3 == c1 ); + + std::fclose(file); +} + +int main () +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/ext/stdio_sync_filebuf/char/12048-2.cc b/libstdc++-v3/testsuite/ext/stdio_sync_filebuf/char/12048-2.cc new file mode 100644 index 00000000000..66192548b03 --- /dev/null +++ b/libstdc++-v3/testsuite/ext/stdio_sync_filebuf/char/12048-2.cc @@ -0,0 +1,46 @@ +// 2003-05-01 Petur Runolfsson + +// 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. + +#include +#include + +// libstdc++/12048 +void test03() +{ + bool test __attribute__((unused)) = true; + const char* name = "cin_unget-1.txt"; + + std::FILE* file = std::fopen(name, "r"); + __gnu_cxx::stdio_sync_filebuf sbuf(file); + int c1 = sbuf.sbumpc(); + VERIFY( c1 != EOF ); + int c2 = sbuf.sungetc(); + VERIFY( c2 != EOF ); + int c3 = std::fgetc(file); + VERIFY( c3 == c1 ); + + std::fclose(file); +} + +int main () +{ + test03(); + return 0; +} diff --git a/libstdc++-v3/testsuite/ext/stdio_sync_filebuf/char/12048-3.cc b/libstdc++-v3/testsuite/ext/stdio_sync_filebuf/char/12048-3.cc new file mode 100644 index 00000000000..6039e15cfe8 --- /dev/null +++ b/libstdc++-v3/testsuite/ext/stdio_sync_filebuf/char/12048-3.cc @@ -0,0 +1,46 @@ +// 2003-05-01 Petur Runolfsson + +// 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. + +#include +#include + +// libstdc++/12048 +void test04() +{ + bool test __attribute__((unused)) = true; + const char* name = "cin_unget-1.txt"; + + std::FILE* file = std::fopen(name, "r"); + __gnu_cxx::stdio_sync_filebuf sbuf(file); + char buf[2]; + VERIFY( sbuf.sgetn(buf, 2) == 2 ); + int c2 = sbuf.sungetc(); + VERIFY( c2 != EOF ); + int c3 = sbuf.sbumpc(); + VERIFY( c3 == std::char_traits::to_int_type(buf[1]) ); + + std::fclose(file); +} + +int main () +{ + test04(); + return 0; +} diff --git a/libstdc++-v3/testsuite/ext/stdio_sync_filebuf/char/12048-4.cc b/libstdc++-v3/testsuite/ext/stdio_sync_filebuf/char/12048-4.cc new file mode 100644 index 00000000000..5372b68e9fa --- /dev/null +++ b/libstdc++-v3/testsuite/ext/stdio_sync_filebuf/char/12048-4.cc @@ -0,0 +1,46 @@ +// 2003-05-01 Petur Runolfsson + +// 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. + +#include +#include + +// libstdc++/12048 +void test05() +{ + bool test __attribute__((unused)) = true; + const char* name = "cin_unget-1.txt"; + + std::FILE* file = std::fopen(name, "r"); + __gnu_cxx::stdio_sync_filebuf sbuf(file); + char buf[2]; + VERIFY( sbuf.sgetn(buf, 2) == 2 ); + int c2 = sbuf.sungetc(); + VERIFY( c2 != EOF ); + int c3 = std::fgetc(file); + VERIFY( c3 == std::char_traits::to_int_type(buf[1]) ); + + std::fclose(file); +} + +int main () +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/ext/stdio_sync_filebuf_wchar_t.cc b/libstdc++-v3/testsuite/ext/stdio_sync_filebuf/wchar_t/1.cc similarity index 54% rename from libstdc++-v3/testsuite/ext/stdio_sync_filebuf_wchar_t.cc rename to libstdc++-v3/testsuite/ext/stdio_sync_filebuf/wchar_t/1.cc index 96831c3c2f4..728602155c3 100644 --- a/libstdc++-v3/testsuite/ext/stdio_sync_filebuf_wchar_t.cc +++ b/libstdc++-v3/testsuite/ext/stdio_sync_filebuf/wchar_t/1.cc @@ -58,85 +58,8 @@ void test01() fclose(fin); } -// libstdc++/12048 -void test02() -{ - bool test __attribute__((unused)) = true; - const char* name = "cin_unget-1.txt"; - - std::FILE* file = std::fopen(name, "r"); - __gnu_cxx::stdio_sync_filebuf sbuf(file); - std::wint_t c1 = sbuf.sbumpc(); - VERIFY( c1 != WEOF ); - std::wint_t c2 = sbuf.sungetc(); - VERIFY( c2 != WEOF ); - std::wint_t c3 = sbuf.sbumpc(); - VERIFY( c3 == c1 ); - - std::fclose(file); -} - -// libstdc++/12048 -void test03() -{ - bool test __attribute__((unused)) = true; - const char* name = "cin_unget-1.txt"; - - std::FILE* file = std::fopen(name, "r"); - __gnu_cxx::stdio_sync_filebuf sbuf(file); - std::wint_t c1 = sbuf.sbumpc(); - VERIFY( c1 != WEOF ); - std::wint_t c2 = sbuf.sungetc(); - VERIFY( c2 != WEOF ); - std::wint_t c3 = std::fgetwc(file); - VERIFY( c3 == c1 ); - - std::fclose(file); -} - -// libstdc++/12048 -void test04() -{ - bool test __attribute__((unused)) = true; - const char* name = "cin_unget-1.txt"; - - std::FILE* file = std::fopen(name, "r"); - __gnu_cxx::stdio_sync_filebuf sbuf(file); - wchar_t buf[2]; - VERIFY( sbuf.sgetn(buf, 2) == 2 ); - std::wint_t c2 = sbuf.sungetc(); - VERIFY( c2 != WEOF ); - std::wint_t c3 = sbuf.sbumpc(); - VERIFY( c3 == std::char_traits::to_int_type(buf[1]) ); - - std::fclose(file); -} - -// libstdc++/12048 -void test05() -{ - bool test __attribute__((unused)) = true; - const char* name = "cin_unget-1.txt"; - - std::FILE* file = std::fopen(name, "r"); - __gnu_cxx::stdio_sync_filebuf sbuf(file); - wchar_t buf[2]; - VERIFY( sbuf.sgetn(buf, 2) == 2 ); - std::wint_t c2 = sbuf.sungetc(); - VERIFY( c2 != WEOF ); - std::wint_t c3 = std::fgetwc(file); - VERIFY( c3 == std::char_traits::to_int_type(buf[1]) ); - - std::fclose(file); -} - int main () { test01(); - test02(); - test03(); - test04(); - test05(); - return 0; } diff --git a/libstdc++-v3/testsuite/ext/stdio_sync_filebuf/wchar_t/12948-1.cc b/libstdc++-v3/testsuite/ext/stdio_sync_filebuf/wchar_t/12948-1.cc new file mode 100644 index 00000000000..5329ba8b1ce --- /dev/null +++ b/libstdc++-v3/testsuite/ext/stdio_sync_filebuf/wchar_t/12948-1.cc @@ -0,0 +1,46 @@ +// 2003-05-01 Petur Runolfsson + +// 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. + +#include +#include + +// libstdc++/12048 +void test02() +{ + bool test __attribute__((unused)) = true; + const char* name = "cin_unget-1.txt"; + + std::FILE* file = std::fopen(name, "r"); + __gnu_cxx::stdio_sync_filebuf sbuf(file); + std::wint_t c1 = sbuf.sbumpc(); + VERIFY( c1 != WEOF ); + std::wint_t c2 = sbuf.sungetc(); + VERIFY( c2 != WEOF ); + std::wint_t c3 = sbuf.sbumpc(); + VERIFY( c3 == c1 ); + + std::fclose(file); +} + +int main () +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/ext/stdio_sync_filebuf/wchar_t/12948-2.cc b/libstdc++-v3/testsuite/ext/stdio_sync_filebuf/wchar_t/12948-2.cc new file mode 100644 index 00000000000..285969bde4c --- /dev/null +++ b/libstdc++-v3/testsuite/ext/stdio_sync_filebuf/wchar_t/12948-2.cc @@ -0,0 +1,46 @@ +// 2003-05-01 Petur Runolfsson + +// 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. + +#include +#include + +// libstdc++/12048 +void test03() +{ + bool test __attribute__((unused)) = true; + const char* name = "cin_unget-1.txt"; + + std::FILE* file = std::fopen(name, "r"); + __gnu_cxx::stdio_sync_filebuf sbuf(file); + std::wint_t c1 = sbuf.sbumpc(); + VERIFY( c1 != WEOF ); + std::wint_t c2 = sbuf.sungetc(); + VERIFY( c2 != WEOF ); + std::wint_t c3 = std::fgetwc(file); + VERIFY( c3 == c1 ); + + std::fclose(file); +} + +int main () +{ + test03(); + return 0; +} diff --git a/libstdc++-v3/testsuite/ext/stdio_sync_filebuf/wchar_t/12948-3.cc b/libstdc++-v3/testsuite/ext/stdio_sync_filebuf/wchar_t/12948-3.cc new file mode 100644 index 00000000000..b006898b33b --- /dev/null +++ b/libstdc++-v3/testsuite/ext/stdio_sync_filebuf/wchar_t/12948-3.cc @@ -0,0 +1,46 @@ +// 2003-05-01 Petur Runolfsson + +// 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. + +#include +#include + +// libstdc++/12048 +void test04() +{ + bool test __attribute__((unused)) = true; + const char* name = "cin_unget-1.txt"; + + std::FILE* file = std::fopen(name, "r"); + __gnu_cxx::stdio_sync_filebuf sbuf(file); + wchar_t buf[2]; + VERIFY( sbuf.sgetn(buf, 2) == 2 ); + std::wint_t c2 = sbuf.sungetc(); + VERIFY( c2 != WEOF ); + std::wint_t c3 = sbuf.sbumpc(); + VERIFY( c3 == std::char_traits::to_int_type(buf[1]) ); + + std::fclose(file); +} + +int main () +{ + test04(); + return 0; +} diff --git a/libstdc++-v3/testsuite/ext/stdio_sync_filebuf/wchar_t/12948-4.cc b/libstdc++-v3/testsuite/ext/stdio_sync_filebuf/wchar_t/12948-4.cc new file mode 100644 index 00000000000..704a75305b4 --- /dev/null +++ b/libstdc++-v3/testsuite/ext/stdio_sync_filebuf/wchar_t/12948-4.cc @@ -0,0 +1,46 @@ +// 2003-05-01 Petur Runolfsson + +// 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. + +#include +#include + +// libstdc++/12048 +void test05() +{ + bool test __attribute__((unused)) = true; + const char* name = "cin_unget-1.txt"; + + std::FILE* file = std::fopen(name, "r"); + __gnu_cxx::stdio_sync_filebuf sbuf(file); + wchar_t buf[2]; + VERIFY( sbuf.sgetn(buf, 2) == 2 ); + std::wint_t c2 = sbuf.sungetc(); + VERIFY( c2 != WEOF ); + std::wint_t c3 = std::fgetwc(file); + VERIFY( c3 == std::char_traits::to_int_type(buf[1]) ); + + std::fclose(file); +} + +int main () +{ + test05(); + return 0; +}