Commit 4c620c39 by Petur Runolfsson Committed by Benjamin Kosnik

re PR libstdc++/12048 (unget does not work)


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
parent 149639d4
......@@ -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)
......
// 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;
}
// 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;
}
// 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;
}
// 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;
}
// 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;
}
// 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;
}
// 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;
}
// 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;
}
// 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;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment