11460.cc 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // { dg-options "-Wno-deprecated" }
  2. // Copyright (C) 2003-2022 Free Software Foundation, Inc.
  3. //
  4. // This file is part of the GNU ISO C++ Library. This library is free
  5. // software; you can redistribute it and/or modify it under the
  6. // terms of the GNU General Public License as published by the
  7. // Free Software Foundation; either version 3, or (at your option)
  8. // any later version.
  9. // This library is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. // You should have received a copy of the GNU General Public License along
  14. // with this library; see the file COPYING3. If not see
  15. // <http://www.gnu.org/licenses/>.
  16. #include <strstream>
  17. #include <testsuite_hooks.h>
  18. class Buf : public std::strstreambuf
  19. {
  20. public:
  21. Buf(const char* p, std::streamsize n)
  22. : std::strstreambuf(p, n)
  23. { }
  24. int_type pub_pbackfail(int_type c = traits_type::eof())
  25. {
  26. return pbackfail(c);
  27. }
  28. };
  29. // libstdc++/11460
  30. void test01()
  31. {
  32. typedef std::strstreambuf::traits_type Traits;
  33. const char str[] = "a\xff";
  34. Buf buf(str, 2);
  35. Traits::int_type a = Traits::to_int_type('a');
  36. VERIFY( buf.sbumpc() == a );
  37. VERIFY( buf.sungetc() == a );
  38. VERIFY( buf.sbumpc() == a );
  39. VERIFY( buf.sputbackc('a') == a );
  40. VERIFY( buf.sbumpc() == a );
  41. VERIFY( buf.pub_pbackfail() != Traits::eof() );
  42. VERIFY( buf.sbumpc() == a );
  43. VERIFY( buf.pub_pbackfail(a) == a );
  44. buf.sbumpc();
  45. Traits::int_type xff = Traits::to_int_type('\xff');
  46. VERIFY( buf.sbumpc() == xff );
  47. VERIFY( buf.sungetc() == xff );
  48. VERIFY( buf.sbumpc() == xff );
  49. VERIFY( buf.sputbackc('\xff') == xff );
  50. VERIFY( buf.sbumpc() == xff );
  51. VERIFY( buf.pub_pbackfail() != Traits::eof() );
  52. VERIFY( buf.sbumpc() == xff );
  53. VERIFY( buf.pub_pbackfail(xff) == xff );
  54. }
  55. int main()
  56. {
  57. test01();
  58. return 0;
  59. }