diff options
author | Paolo Carlini <paolo.carlini@oracle.com> | 2009-01-01 10:08:31 +0000 |
---|---|---|
committer | Paolo Carlini <paolo@gcc.gnu.org> | 2009-01-01 10:08:31 +0000 |
commit | 91a96b33a9b71785d7372b87824a40da43e5384b (patch) | |
tree | 2f7f4c2f400081d70719dc09252bf8c9ece1c01e /libstdc++-v3/testsuite | |
parent | edc31cc1297aa61bcc8b5448778152733441ffe3 (diff) | |
download | gcc-91a96b33a9b71785d7372b87824a40da43e5384b.tar.gz |
re PR libstdc++/38678 ([DR XXX] istream::read() calls streambuf::sgetn())
2009-01-01 Paolo Carlini <paolo.carlini@oracle.com>
PR libstdc++/38678
* include/std/istream (basic_istream<>::_M_read): New.
* include/bits/istream.tcc (basic_istream<>::_M_read): Define.
(basic_istream<>::read, basic_istream<>::readsome): Use it.
* include/std/ostream (basic_ostream<>::_M_write_): New.
(basic_ostream<>::_M_write): Adjust.
* include/bits/ostream.tcc (basic_ostream<>::_M_write_): Define.
* testsuite/27_io/basic_istream/read/char/38678.cc: New.
* testsuite/27_io/basic_istream/read/wchar_t/38678.cc: Likewise.
* testsuite/27_io/basic_ostream/write/char/38678.cc: Likewise.
* testsuite/27_io/basic_ostream/write/wchar_t/38678.cc: Likewise.
From-SVN: r142994
Diffstat (limited to 'libstdc++-v3/testsuite')
4 files changed, 260 insertions, 0 deletions
diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/read/char/38678.cc b/libstdc++-v3/testsuite/27_io/basic_istream/read/char/38678.cc new file mode 100644 index 00000000000..e4865af5c6c --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/read/char/38678.cc @@ -0,0 +1,67 @@ +// Copyright (C) 2009 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, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 27.6.1.3 unformatted input functions + +#include <istream> +#include <streambuf> +#include <testsuite_hooks.h> + +// libstdc++/38678 +void test01() +{ + bool test __attribute__((unused)) = true; + + static char x = '0'; + + struct : std::streambuf + { + char c; + + int_type + underflow() + { + c = x++; + setg(&c, &c, &c + 1); + return traits_type::to_int_type(c); + } + + std::streamsize + xsgetn(char*, std::streamsize) + { + VERIFY( !"xsgetn should not be called" ); + return 0; + } + } sb; + + std::istream in(&sb); + + char s[4] = ""; + + in.read(s, 4); + + VERIFY( in.good() ); + VERIFY( 4 == in.gcount() ); + VERIFY( '0' == s[0] && '1' == s[1] && '2' == s[2] && '3' == s[3] ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/read/wchar_t/38678.cc b/libstdc++-v3/testsuite/27_io/basic_istream/read/wchar_t/38678.cc new file mode 100644 index 00000000000..fcf1b88ce9d --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/read/wchar_t/38678.cc @@ -0,0 +1,67 @@ +// Copyright (C) 2009 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, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 27.6.1.3 unformatted input functions + +#include <istream> +#include <streambuf> +#include <testsuite_hooks.h> + +// libstdc++/38678 +void test01() +{ + bool test __attribute__((unused)) = true; + + static wchar_t x = L'0'; + + struct : std::wstreambuf + { + wchar_t c; + + int_type + underflow() + { + c = x++; + setg(&c, &c, &c + 1); + return traits_type::to_int_type(c); + } + + std::streamsize + xsgetn(wchar_t*, std::streamsize) + { + VERIFY( !"xsgetn should not be called" ); + return 0; + } + } sb; + + std::wistream in(&sb); + + wchar_t s[4] = L""; + + in.read(s, 4); + + VERIFY( in.good() ); + VERIFY( 4 == in.gcount() ); + VERIFY( L'0' == s[0] && L'1' == s[1] && L'2' == s[2] && L'3' == s[3] ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/write/char/38678.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/write/char/38678.cc new file mode 100644 index 00000000000..6c7fee1b135 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/write/char/38678.cc @@ -0,0 +1,63 @@ +// Copyright (C) 2009 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, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 27.6.2.6 unformatted output functions + +#include <ostream> +#include <streambuf> +#include <testsuite_hooks.h> + +// libstdc++/38678 +void test01() +{ + bool test __attribute__((unused)) = true; + + static char s[4] = ""; + static unsigned i = 0; + + struct : std::streambuf + { + int_type + overflow(int_type c) + { + s[i++] = traits_type::to_char_type(c); + return traits_type::not_eof(c); + } + + std::streamsize + xsputn(const char*, std::streamsize) + { + VERIFY( !"xsputn should not be called" ); + return 0; + } + } sb; + + std::ostream out(&sb); + + out.write("0123", 4); + + VERIFY( out.good() ); + VERIFY( 4 == i ); + VERIFY( '0' == s[0] && '1' == s[1] && '2' == s[2] && '3' == s[3] ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/write/wchar_t/38678.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/write/wchar_t/38678.cc new file mode 100644 index 00000000000..8a9d184eabd --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/write/wchar_t/38678.cc @@ -0,0 +1,63 @@ +// Copyright (C) 2009 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, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 27.6.2.6 unformatted output functions + +#include <ostream> +#include <streambuf> +#include <testsuite_hooks.h> + +// libstdc++/38678 +void test01() +{ + bool test __attribute__((unused)) = true; + + static wchar_t s[4] = L""; + static unsigned i = 0; + + struct : std::wstreambuf + { + int_type + overflow(int_type c) + { + s[i++] = traits_type::to_char_type(c); + return traits_type::not_eof(c); + } + + std::streamsize + xsputn(const wchar_t*, std::streamsize) + { + VERIFY( !"xsputn should not be called" ); + return 0; + } + } sb; + + std::wostream out(&sb); + + out.write(L"0123", 4); + + VERIFY( out.good() ); + VERIFY( 4 == i ); + VERIFY( L'0' == s[0] && L'1' == s[1] && L'2' == s[2] && L'3' == s[3] ); +} + +int main() +{ + test01(); + return 0; +} |