Index: include/ext/stdio_sync_filebuf.h
===================================================================
RCS file: /home/petur/cvsroot/gcc/libstdc++-v3/include/ext/stdio_sync_filebuf.h,v
retrieving revision 1.1.1.2
diff -c -3 -p -r1.1.1.2 stdio_sync_filebuf.h
*** include/ext/stdio_sync_filebuf.h	6 Jul 2003 20:51:55 -0000	1.1.1.2
--- include/ext/stdio_sync_filebuf.h	29 Aug 2003 07:13:36 -0000
*************** namespace __gnu_cxx
*** 57,66 ****
    template<typename _CharT, typename _Traits = std::char_traits<_CharT> >
      class stdio_sync_filebuf : public std::basic_streambuf<_CharT, _Traits>
      {
!     private:
!       std::__c_file* const _M_file;
! 
!      public:
        // Types:
        typedef _CharT                  	        	char_type;
        typedef _Traits		                    	traits_type;
--- 57,63 ----
    template<typename _CharT, typename _Traits = std::char_traits<_CharT> >
      class stdio_sync_filebuf : public std::basic_streambuf<_CharT, _Traits>
      {
!     public:
        // Types:
        typedef _CharT                  	        	char_type;
        typedef _Traits		                    	traits_type;
*************** namespace __gnu_cxx
*** 68,75 ****
        typedef typename traits_type::pos_type 		pos_type;
        typedef typename traits_type::off_type 		off_type;
  
        explicit 
!       stdio_sync_filebuf(std::__c_file* __f) : _M_file(__f) { }
  
      protected:
  
--- 65,83 ----
        typedef typename traits_type::pos_type 		pos_type;
        typedef typename traits_type::off_type 		off_type;
  
+     private:
+       // Underlying stdio FILE
+       std::__c_file* const _M_file;
+       
+       // Last character gotten. This is used when pbackfail is
+       // called from basic_streambuf::sungetc()
+       int_type _M_unget_buf;
+ 
+     public:
        explicit 
!       stdio_sync_filebuf(std::__c_file* __f)
!       : _M_file(__f), _M_unget_buf(traits_type::eof())
!       { }
  
      protected:
  
*************** namespace __gnu_cxx
*** 91,101 ****
  
        virtual int_type
        uflow()
!       { return this->syncgetc(); }
  
        virtual int_type
        pbackfail(int_type __c = traits_type::eof())
!       { return this->syncungetc(__c); }
  
        virtual std::streamsize
        xsgetn(char_type* __s, std::streamsize __n);
--- 99,131 ----
  
        virtual int_type
        uflow()
!       {
! 	// Store the gotten character in case we need to unget it.
! 	_M_unget_buf = this->syncgetc();
! 	return _M_unget_buf;
!       }
  
        virtual int_type
        pbackfail(int_type __c = traits_type::eof())
!       {
! 	int_type __ret;
! 	const int_type __eof = traits_type::eof();
! 
! 	// Check if the unget or putback was requested
! 	if (traits_type::eq_int_type(__c, __eof)) // unget
! 	  {
! 	    if (!traits_type::eq_int_type(_M_unget_buf, __eof))
! 	      __ret = this->syncungetc(_M_unget_buf);
! 	    else // buffer invalid, fail.
! 	      __ret = __eof;
! 	  }
! 	else // putback
! 	  __ret = this->syncungetc(__c);
! 
! 	// The buffered character is no longer valid, discard it.
! 	_M_unget_buf = __eof;
! 	return __ret;
!       }
  
        virtual std::streamsize
        xsgetn(char_type* __s, std::streamsize __n);
*************** namespace __gnu_cxx
*** 179,185 ****
    template<>
      inline std::streamsize
      stdio_sync_filebuf<char>::xsgetn(char* __s, std::streamsize __n)
!     { return std::fread(__s, 1, __n, _M_file); }
  
    template<>
      inline std::streamsize
--- 209,222 ----
    template<>
      inline std::streamsize
      stdio_sync_filebuf<char>::xsgetn(char* __s, std::streamsize __n)
!     {
!       std::streamsize __ret = std::fread(__s, 1, __n, _M_file);
!       if (__ret > 0)
! 	_M_unget_buf = traits_type::to_int_type(__s[__ret - 1]);
!       else
! 	_M_unget_buf = traits_type::eof();
!       return __ret;
!     }
  
    template<>
      inline std::streamsize
*************** namespace __gnu_cxx
*** 213,221 ****
  	  int_type __c = this->syncgetc();
  	  if (traits_type::eq_int_type(__c, __eof))
  	    break;
! 	  *__s++ = __c;
  	  ++__ret;
  	}
        return __ret;
      }
        
--- 250,263 ----
  	  int_type __c = this->syncgetc();
  	  if (traits_type::eq_int_type(__c, __eof))
  	    break;
! 	  __s[__ret] = traits_type::to_char_type(__c);
  	  ++__ret;
  	}
+ 
+       if (__ret > 0)
+ 	_M_unget_buf = traits_type::to_int_type(__s[__ret - 1]);
+       else
+ 	_M_unget_buf = traits_type::eof();
        return __ret;
      }
        
Index: testsuite/27_io/objects/char/12048-1.cc
===================================================================
RCS file: testsuite/27_io/objects/char/12048-1.cc
diff -N testsuite/27_io/objects/char/12048-1.cc
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- testsuite/27_io/objects/char/12048-1.cc	28 Aug 2003 19:54:05 -0000
***************
*** 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);
+ 
+   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;
+ }
Index: testsuite/27_io/objects/char/12048-2.cc
===================================================================
RCS file: testsuite/27_io/objects/char/12048-2.cc
diff -N testsuite/27_io/objects/char/12048-2.cc
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- testsuite/27_io/objects/char/12048-2.cc	28 Aug 2003 22:15:05 -0000
***************
*** 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;
+ }
Index: testsuite/27_io/objects/char/12048-3.cc
===================================================================
RCS file: testsuite/27_io/objects/char/12048-3.cc
diff -N testsuite/27_io/objects/char/12048-3.cc
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- testsuite/27_io/objects/char/12048-3.cc	28 Aug 2003 22:16:18 -0000
***************
*** 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;
+ }
Index: testsuite/27_io/objects/char/12048-4.cc
===================================================================
RCS file: testsuite/27_io/objects/char/12048-4.cc
diff -N testsuite/27_io/objects/char/12048-4.cc
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- testsuite/27_io/objects/char/12048-4.cc	28 Aug 2003 22:16:28 -0000
***************
*** 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;
+ }
Index: testsuite/27_io/objects/char/12048-5.cc
===================================================================
RCS file: testsuite/27_io/objects/char/12048-5.cc
diff -N testsuite/27_io/objects/char/12048-5.cc
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- testsuite/27_io/objects/char/12048-5.cc	28 Aug 2003 22:18:19 -0000
***************
*** 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;
+ }
Index: testsuite/27_io/objects/char/12048.cc
===================================================================
RCS file: testsuite/27_io/objects/char/12048.cc
diff -N testsuite/27_io/objects/char/12048.cc
*** testsuite/27_io/objects/char/12048.cc	28 Aug 2003 17:43:20 -0000	1.1.1.1
--- /dev/null	1 Jan 1970 00:00:00 -0000
***************
*** 1,42 ****
- // 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);
- 
-   char c1;
-   char c2;
-   std::cin.get(c1);
-   std::cin.unget();
-   std::cin.get(c2);
-   VERIFY (c1 == c2);
- }
- 
- int main(void)
- {
-   test01();
-   return 0;
- }
--- 0 ----
Index: testsuite/27_io/objects/wchar_t/12048-1.cc
===================================================================
RCS file: testsuite/27_io/objects/wchar_t/12048-1.cc
diff -N testsuite/27_io/objects/wchar_t/12048-1.cc
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- testsuite/27_io/objects/wchar_t/12048-1.cc	28 Aug 2003 20:24:45 -0000
***************
*** 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;
+ }
Index: testsuite/27_io/objects/wchar_t/12048-2.cc
===================================================================
RCS file: testsuite/27_io/objects/wchar_t/12048-2.cc
diff -N testsuite/27_io/objects/wchar_t/12048-2.cc
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- testsuite/27_io/objects/wchar_t/12048-2.cc	28 Aug 2003 22:17:26 -0000
***************
*** 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;
+ }
Index: testsuite/27_io/objects/wchar_t/12048-3.cc
===================================================================
RCS file: testsuite/27_io/objects/wchar_t/12048-3.cc
diff -N testsuite/27_io/objects/wchar_t/12048-3.cc
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- testsuite/27_io/objects/wchar_t/12048-3.cc	28 Aug 2003 22:17:45 -0000
***************
*** 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;
+ }
Index: testsuite/27_io/objects/wchar_t/12048-4.cc
===================================================================
RCS file: testsuite/27_io/objects/wchar_t/12048-4.cc
diff -N testsuite/27_io/objects/wchar_t/12048-4.cc
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- testsuite/27_io/objects/wchar_t/12048-4.cc	28 Aug 2003 22:18:09 -0000
***************
*** 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;
+ }
Index: testsuite/27_io/objects/wchar_t/12048-5.cc
===================================================================
RCS file: testsuite/27_io/objects/wchar_t/12048-5.cc
diff -N testsuite/27_io/objects/wchar_t/12048-5.cc
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- testsuite/27_io/objects/wchar_t/12048-5.cc	28 Aug 2003 22:17:01 -0000
***************
*** 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;
+ }
Index: testsuite/ext/stdio_sync_filebuf_char.cc
===================================================================
RCS file: /home/petur/cvsroot/gcc/libstdc++-v3/testsuite/ext/stdio_sync_filebuf_char.cc,v
retrieving revision 1.1.1.1
diff -c -3 -p -r1.1.1.1 stdio_sync_filebuf_char.cc
*** testsuite/ext/stdio_sync_filebuf_char.cc	22 Jun 2003 17:33:07 -0000	1.1.1.1
--- testsuite/ext/stdio_sync_filebuf_char.cc	28 Aug 2003 20:04:59 -0000
*************** void test01()
*** 52,64 ****
    VERIFY( sbuf.sgetn(buf, 5) == 5 );
    VERIFY( !memcmp(buf, c_lit + 3, 5) );
    VERIFY( getc(fin) == c_lit[8] );
-   VERIFY( sbuf.sungetc() == EOF );
  
    fclose(fin);
  }
  
  int main ()
  {
    test01();
    return 0;
  }
--- 52,140 ----
    VERIFY( sbuf.sgetn(buf, 5) == 5 );
    VERIFY( !memcmp(buf, c_lit + 3, 5) );
    VERIFY( getc(fin) == c_lit[8] );
  
    fclose(fin);
  }
  
+ // libstdc++/12048
+ void test02()
+ {
+   bool test = true;
+   const char* name = "cin_unget-1.txt";
+ 
+   std::FILE* file = std::fopen(name, "r");
+   __gnu_cxx::stdio_sync_filebuf<char> 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 = true;
+   const char* name = "cin_unget-1.txt";
+ 
+   std::FILE* file = std::fopen(name, "r");
+   __gnu_cxx::stdio_sync_filebuf<char> 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 = true;
+   const char* name = "cin_unget-1.txt";
+ 
+   std::FILE* file = std::fopen(name, "r");
+   __gnu_cxx::stdio_sync_filebuf<char> 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<char>::to_int_type(buf[1]) );
+ 
+   std::fclose(file);
+ }
+ 
+ // libstdc++/12048
+ void test05()
+ {
+   bool test = true;
+   const char* name = "cin_unget-1.txt";
+ 
+   std::FILE* file = std::fopen(name, "r");
+   __gnu_cxx::stdio_sync_filebuf<char> 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<char>::to_int_type(buf[1]) );
+ 
+   std::fclose(file);
+ }
+ 
  int main ()
  {
    test01();
+   test02();
+   test03();
+   test04();
+   test05();
+ 
    return 0;
  }
Index: testsuite/ext/stdio_sync_filebuf_wchar_t.cc
===================================================================
RCS file: /home/petur/cvsroot/gcc/libstdc++-v3/testsuite/ext/stdio_sync_filebuf_wchar_t.cc,v
retrieving revision 1.1.1.1
diff -c -3 -p -r1.1.1.1 stdio_sync_filebuf_wchar_t.cc
*** testsuite/ext/stdio_sync_filebuf_wchar_t.cc	22 Jun 2003 17:33:08 -0000	1.1.1.1
--- testsuite/ext/stdio_sync_filebuf_wchar_t.cc	28 Aug 2003 22:19:22 -0000
*************** void test01()
*** 53,65 ****
    VERIFY( wsbuf.sgetn(buf, 5) == 5 );
    VERIFY( !wmemcmp(buf, w_lit + 3, 5) );
    VERIFY( getwc(fin) == w_lit[8] );
-   VERIFY( wsbuf.sungetc() == WEOF );
  
    fclose(fin);
  }
  
  int main ()
  {
    test01();
    return 0;
  }
--- 53,141 ----
    VERIFY( wsbuf.sgetn(buf, 5) == 5 );
    VERIFY( !wmemcmp(buf, w_lit + 3, 5) );
    VERIFY( getwc(fin) == w_lit[8] );
  
    fclose(fin);
  }
  
+ // libstdc++/12048
+ void test02()
+ {
+   bool test = true;
+   const char* name = "cin_unget-1.txt";
+ 
+   std::FILE* file = std::fopen(name, "r");
+   __gnu_cxx::stdio_sync_filebuf<wchar_t> 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 = true;
+   const char* name = "cin_unget-1.txt";
+ 
+   std::FILE* file = std::fopen(name, "r");
+   __gnu_cxx::stdio_sync_filebuf<wchar_t> 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 = true;
+   const char* name = "cin_unget-1.txt";
+ 
+   std::FILE* file = std::fopen(name, "r");
+   __gnu_cxx::stdio_sync_filebuf<wchar_t> 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<wchar_t>::to_int_type(buf[1]) );
+ 
+   std::fclose(file);
+ }
+ 
+ // libstdc++/12048
+ void test05()
+ {
+   bool test = true;
+   const char* name = "cin_unget-1.txt";
+ 
+   std::FILE* file = std::fopen(name, "r");
+   __gnu_cxx::stdio_sync_filebuf<wchar_t> 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<wchar_t>::to_int_type(buf[1]) );
+ 
+   std::fclose(file);
+ }
+ 
  int main ()
  {
    test01();
+   test02();
+   test03();
+   test04();
+   test05();
+ 
    return 0;
  }
