]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR libstdc++/12048 (unget does not work)
authorPetur Runolfsson <peturr02@ru.is>
Wed, 3 Sep 2003 14:57:04 +0000 (14:57 +0000)
committerBenjamin Kosnik <bkoz@gcc.gnu.org>
Wed, 3 Sep 2003 14:57:04 +0000 (14:57 +0000)
2003-09-03  Petur Runolfsson  <peturr02@ru.is>

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<char>::xsgetn): Store last read character in
_M_unget_buf, if any, else eof().
(stdio_sync_filebuf<wchar_t>::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

libstdc++-v3/testsuite/27_io/objects/char/12048-1.cc [moved from libstdc++-v3/testsuite/27_io/objects/char/12048.cc with 95% similarity]
libstdc++-v3/testsuite/27_io/objects/char/12048-2.cc [new file with mode: 0644]
libstdc++-v3/testsuite/27_io/objects/char/12048-3.cc [new file with mode: 0644]
libstdc++-v3/testsuite/27_io/objects/char/12048-4.cc [new file with mode: 0644]
libstdc++-v3/testsuite/27_io/objects/char/12048-5.cc [new file with mode: 0644]
libstdc++-v3/testsuite/27_io/objects/wchar_t/12048-1.cc [new file with mode: 0644]
libstdc++-v3/testsuite/27_io/objects/wchar_t/12048-2.cc [new file with mode: 0644]
libstdc++-v3/testsuite/27_io/objects/wchar_t/12048-3.cc [new file with mode: 0644]
libstdc++-v3/testsuite/27_io/objects/wchar_t/12048-4.cc [new file with mode: 0644]
libstdc++-v3/testsuite/27_io/objects/wchar_t/12048-5.cc [new file with mode: 0644]

similarity index 95%
rename from libstdc++-v3/testsuite/27_io/objects/char/12048.cc
rename to libstdc++-v3/testsuite/27_io/objects/char/12048-1.cc
index 575fe35350c4d8ea523bd45bf3ae5ebdf8f0b7ca..7ad336dafe6a4c4a093063ebb269591ff68ee15e 100644 (file)
@@ -32,7 +32,8 @@ test01()
   std::cin.get(c1);
   std::cin.unget();
   std::cin.get(c2);
-  VERIFY (c1 == c2);
+  VERIFY( std::cin.good() );
+  VERIFY( c1 == c2 );
 }
 
 int main(void)
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 (file)
index 0000000..d544d64
--- /dev/null
@@ -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 <iostream>
+#include <cstdio>
+#include <testsuite_hooks.h>
+
+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<char>::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 (file)
index 0000000..2f69b07
--- /dev/null
@@ -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 <iostream>
+#include <testsuite_hooks.h>
+
+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<char>::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 (file)
index 0000000..6c0b28f
--- /dev/null
@@ -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 <iostream>
+#include <cstdio>
+#include <testsuite_hooks.h>
+
+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<char>::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 (file)
index 0000000..884f49e
--- /dev/null
@@ -0,0 +1,55 @@
+// Derived from libstdc++/12048 by LJR <ljrittle@acm.org> with
+// reminder from Petur Runolfsson <peturr02@ru.is>.
+
+// 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 <iostream>
+#include <cstdio>
+#include <testsuite_hooks.h>
+
+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<char>::to_char_type(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 (file)
index 0000000..dbdf1d1
--- /dev/null
@@ -0,0 +1,43 @@
+// Derived from libstdc++/12048 by LJR <ljrittle@acm.org> with
+// reminder from Petur Runolfsson <peturr02@ru.is>.
+
+// 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 <iostream>
+#include <testsuite_hooks.h>
+
+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 (file)
index 0000000..f96302a
--- /dev/null
@@ -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 <iostream>
+#include <cstdio>
+#include <cwchar>
+#include <testsuite_hooks.h>
+
+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<wchar_t>::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 (file)
index 0000000..568b6a1
--- /dev/null
@@ -0,0 +1,43 @@
+// Derived from libstdc++/12048 by LJR <ljrittle@acm.org> with
+// reminder from Petur Runolfsson <peturr02@ru.is>.
+
+// 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 <iostream>
+#include <cwchar>
+#include <testsuite_hooks.h>
+
+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<wchar_t>::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 (file)
index 0000000..5096cd0
--- /dev/null
@@ -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 <iostream>
+#include <cstdio>
+#include <cwchar>
+#include <testsuite_hooks.h>
+
+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<wchar_t>::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 (file)
index 0000000..bc965fd
--- /dev/null
@@ -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 <iostream>
+#include <cstdio>
+#include <cwchar>
+#include <testsuite_hooks.h>
+
+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<wchar_t>::to_char_type(c2) );
+    }
+}
+
+int main(void)
+{
+  test01();
+  return 0;
+}