From: Petur Runolfsson Date: Wed, 3 Sep 2003 14:57:04 +0000 (+0000) Subject: re PR libstdc++/12048 (unget does not work) X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=4c620c398ef5e70e2fe3c6aa7b210b8416d460df;p=gcc.git re PR libstdc++/12048 (unget does not work) 2003-09-03 Petur Runolfsson PR libstdc++/12048 * include/ext/stdio_sync_filebuf.h (stdio_sync_filebuf::_M_unget_buf): Declare it. (stdio_sync_filebuf::stdio_sync_filebuf): Initialize _M_unget_buf. (stdio_sync_filebuf::uflow): Store the returned character in _M_unget_buf. (stdio_sync_filebuf::pbackfail): If argument is eof(), pass _M_unget_buf to syncungetc(). Set _M_unget_buf to eof(). (stdio_sync_filebuf::xsgetn): Store last read character in _M_unget_buf, if any, else eof(). (stdio_sync_filebuf::xsgetn: Store last read character in _M_unget_buf, if any, else eof(). * testsuite/27_io/objects/char/12048.cc: Rename to... * testsuite/27_io/objects/char/12048-1.cc: ...this. * testsuite/27_io/objects/char/12048-2.cc: New test. * testsuite/27_io/objects/char/12048-3.cc: New test. * testsuite/27_io/objects/char/12048-4.cc: New test. * testsuite/27_io/objects/char/12048-5.cc: New test. XFAIL. * testsuite/27_io/objects/wchar_t/12048-1.cc: New test. * testsuite/27_io/objects/wchar_t/12048-2.cc: New test. * testsuite/27_io/objects/wchar_t/12048-3.cc: New test. * testsuite/27_io/objects/wchar_t/12048-4.cc: New test. * testsuite/27_io/objects/wchar_t/12048-5.cc: New test. XFAIL. * testsuite/ext/stdio_sync_filebuf_char.cc (test02, test03, test04, test05): New tests. * testsuite/ext/stdio_sync_filebuf_wchar_t.cc (test02, test03, test04, test05): New tests. From-SVN: r71027 --- diff --git a/libstdc++-v3/testsuite/27_io/objects/char/12048-1.cc b/libstdc++-v3/testsuite/27_io/objects/char/12048-1.cc new file mode 100644 index 00000000000..7ad336dafe6 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/objects/char/12048-1.cc @@ -0,0 +1,43 @@ +// Derived from libstdc++/12048 by LJR with +// reminder from Petur Runolfsson . + +// 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. + +#include +#include + +void +test01() +{ + std::freopen("cin_unget-1.txt", "r", stdin); + + char c1; + char c2; + std::cin.get(c1); + std::cin.unget(); + std::cin.get(c2); + VERIFY( std::cin.good() ); + VERIFY( c1 == c2 ); +} + +int main(void) +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/objects/char/12048-2.cc b/libstdc++-v3/testsuite/27_io/objects/char/12048-2.cc new file mode 100644 index 00000000000..d544d644065 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/objects/char/12048-2.cc @@ -0,0 +1,41 @@ +// 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. + +#include +#include +#include + +void +test01() +{ + std::freopen("cin_unget-1.txt", "r", stdin); + + char c1; + int c2; + std::cin.get(c1); + std::cin.unget(); + VERIFY( std::cin.good() ); + c2 = std::fgetc(stdin); + VERIFY( c2 == std::char_traits::to_int_type(c1) ); +} + +int main(void) +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/objects/char/12048-3.cc b/libstdc++-v3/testsuite/27_io/objects/char/12048-3.cc new file mode 100644 index 00000000000..2f69b072233 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/objects/char/12048-3.cc @@ -0,0 +1,39 @@ +// 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. + +#include +#include + +void +test01() +{ + std::freopen("cin_unget-1.txt", "r", stdin); + + char buf[2]; + VERIFY( std::cin.rdbuf()->sgetn(buf, 2) == 2 ); + int c1 = std::cin.rdbuf()->sungetc(); + int c2 = std::cin.rdbuf()->sbumpc(); + VERIFY( c1 == std::char_traits::to_int_type(buf[1]) ); + VERIFY( c2 == c1 ); +} + +int main(void) +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/objects/char/12048-4.cc b/libstdc++-v3/testsuite/27_io/objects/char/12048-4.cc new file mode 100644 index 00000000000..6c0b28fe4db --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/objects/char/12048-4.cc @@ -0,0 +1,40 @@ +// 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. + +#include +#include +#include + +void +test01() +{ + std::freopen("cin_unget-1.txt", "r", stdin); + + char buf[2]; + VERIFY( std::cin.rdbuf()->sgetn(buf, 2) == 2 ); + int c1 = std::cin.rdbuf()->sungetc(); + int c2 = std::fgetc(stdin); + VERIFY( c1 == std::char_traits::to_int_type(buf[1]) ); + VERIFY( c2 == c1 ); +} + +int main(void) +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/objects/char/12048-5.cc b/libstdc++-v3/testsuite/27_io/objects/char/12048-5.cc new file mode 100644 index 00000000000..884f49e9010 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/objects/char/12048-5.cc @@ -0,0 +1,55 @@ +// Derived from libstdc++/12048 by LJR with +// reminder from Petur Runolfsson . + +// 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. + +// DR 49 states that cin.rdbuf()->sbumpc() and fgetc(stdin) should be +// equivalent and interchangable. Currently however, cin.rdbuf()->sungetc() +// only returns characters that were read with cin.rdbuf()->sbumpc() + +// { dg-do run { xfail *-*-* } } + +#include +#include +#include + +void +test01() +{ + std::freopen("cin_unget-1.txt", "r", stdin); + + char c1; + int c2; + char c3; + std::cin.get(c1); + c2 = std::fgetc(stdin); + std::cin.unget(); + if (std::cin.good()) + { + std::cin.get(c3); + VERIFY( std::cin.good() ); + VERIFY( c3 == std::char_traits::to_char_type(c2) ); + } +} + +int main(void) +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/objects/char/12048.cc b/libstdc++-v3/testsuite/27_io/objects/char/12048.cc deleted file mode 100644 index 575fe35350c..00000000000 --- a/libstdc++-v3/testsuite/27_io/objects/char/12048.cc +++ /dev/null @@ -1,42 +0,0 @@ -// Derived from libstdc++/12048 by LJR with -// reminder from Petur Runolfsson . - -// 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. - -#include -#include - -void -test01() -{ - std::freopen("cin_unget-1.txt", "r", stdin); - - char c1; - char c2; - std::cin.get(c1); - std::cin.unget(); - std::cin.get(c2); - VERIFY (c1 == c2); -} - -int main(void) -{ - test01(); - return 0; -} diff --git a/libstdc++-v3/testsuite/27_io/objects/wchar_t/12048-1.cc b/libstdc++-v3/testsuite/27_io/objects/wchar_t/12048-1.cc new file mode 100644 index 00000000000..dbdf1d12f7e --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/objects/wchar_t/12048-1.cc @@ -0,0 +1,43 @@ +// Derived from libstdc++/12048 by LJR with +// reminder from Petur Runolfsson . + +// 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. + +#include +#include + +void +test01() +{ + std::freopen("cin_unget-1.txt", "r", stdin); + + wchar_t c1; + wchar_t c2; + std::wcin.get(c1); + std::wcin.unget(); + std::wcin.get(c2); + VERIFY( std::wcin.good() ); + VERIFY( c1 == c2 ); +} + +int main(void) +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/objects/wchar_t/12048-2.cc b/libstdc++-v3/testsuite/27_io/objects/wchar_t/12048-2.cc new file mode 100644 index 00000000000..f96302ad292 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/objects/wchar_t/12048-2.cc @@ -0,0 +1,42 @@ +// 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. + +#include +#include +#include +#include + +void +test01() +{ + std::freopen("cin_unget-1.txt", "r", stdin); + + wchar_t c1; + std::wint_t c2; + std::wcin.get(c1); + std::wcin.unget(); + VERIFY( std::wcin.good() ); + c2 = std::fgetwc(stdin); + VERIFY( c2 == std::char_traits::to_int_type(c1) ); +} + +int main(void) +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/objects/wchar_t/12048-3.cc b/libstdc++-v3/testsuite/27_io/objects/wchar_t/12048-3.cc new file mode 100644 index 00000000000..568b6a1409a --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/objects/wchar_t/12048-3.cc @@ -0,0 +1,43 @@ +// Derived from libstdc++/12048 by LJR with +// reminder from Petur Runolfsson . + +// 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. + +#include +#include +#include + +void +test01() +{ + std::freopen("cin_unget-1.txt", "r", stdin); + + wchar_t buf[2]; + VERIFY( std::wcin.rdbuf()->sgetn(buf, 2) == 2 ); + std::wint_t c1 = std::wcin.rdbuf()->sungetc(); + std::wint_t c2 = std::wcin.rdbuf()->sbumpc(); + VERIFY( c1 == std::char_traits::to_int_type(buf[1]) ); + VERIFY( c2 == c1 ); +} + +int main(void) +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/objects/wchar_t/12048-4.cc b/libstdc++-v3/testsuite/27_io/objects/wchar_t/12048-4.cc new file mode 100644 index 00000000000..5096cd055e3 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/objects/wchar_t/12048-4.cc @@ -0,0 +1,41 @@ +// 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. + +#include +#include +#include +#include + +void +test01() +{ + std::freopen("cin_unget-1.txt", "r", stdin); + + wchar_t buf[2]; + VERIFY( std::wcin.rdbuf()->sgetn(buf, 2) == 2 ); + wint_t c1 = std::wcin.rdbuf()->sungetc(); + wint_t c2 = std::fgetwc(stdin); + VERIFY( c1 == std::char_traits::to_int_type(buf[1]) ); + VERIFY( c2 == c1 ); +} + +int main(void) +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/objects/wchar_t/12048-5.cc b/libstdc++-v3/testsuite/27_io/objects/wchar_t/12048-5.cc new file mode 100644 index 00000000000..bc965fd35f9 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/objects/wchar_t/12048-5.cc @@ -0,0 +1,53 @@ +// 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. + +// DR 49 states that cin.rdbuf()->sbumpc() and fgetc(stdin) should be +// equivalent and interchangable. Currently however, cin.rdbuf()->sungetc() +// only returns characters that were read with cin.rdbuf()->sbumpc() + +// { dg-do run { xfail *-*-* } } + +#include +#include +#include +#include + +void +test01() +{ + std::freopen("cin_unget-1.txt", "r", stdin); + + wchar_t c1; + std::wint_t c2; + wchar_t c3; + std::wcin.get(c1); + c2 = std::fgetwc(stdin); + std::wcin.unget(); + if (std::wcin.good()) + { + std::wcin.get(c3); + VERIFY( std::wcin.good() ); + VERIFY( c3 == std::char_traits::to_char_type(c2) ); + } +} + +int main(void) +{ + test01(); + return 0; +}