3.cc 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. // Copyright (C) 2017-2022 Free Software Foundation, Inc.
  2. //
  3. // This file is part of the GNU ISO C++ Library. This library is free
  4. // software; you can redistribute it and/or modify it under the
  5. // terms of the GNU General Public License as published by the
  6. // Free Software Foundation; either version 3, or (at your option)
  7. // any later version.
  8. // This library is distributed in the hope that it will be useful,
  9. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. // GNU General Public License for more details.
  12. // You should have received a copy of the GNU General Public License along
  13. // with this library; see the file COPYING3. If not see
  14. // <http://www.gnu.org/licenses/>.
  15. // { dg-do run { target c++11 } }
  16. #include <locale>
  17. #include <streambuf>
  18. #include <testsuite_hooks.h>
  19. struct streambuf : std::streambuf
  20. {
  21. int_type underflow() override
  22. {
  23. if (c != '\0')
  24. {
  25. this->setg(&c, &c, &c + 1);
  26. return *this->gptr();
  27. }
  28. c = '\0';
  29. return traits_type::eof();
  30. }
  31. private:
  32. char c = 'a';
  33. };
  34. void
  35. test01()
  36. {
  37. #ifdef _GLIBCXX_USE_WCHAR_T
  38. struct codecvt : std::codecvt<wchar_t, char, std::mbstate_t> { };
  39. // https://gcc.gnu.org/ml/libstdc++/2017-11/msg00022.html
  40. streambuf sb;
  41. std::wbuffer_convert<codecvt> conv(&sb);
  42. VERIFY( sb.in_avail() == 0 );
  43. wchar_t c = conv.sgetc();
  44. VERIFY( c == L'a' );
  45. #endif
  46. }
  47. void
  48. test02()
  49. {
  50. struct codecvt : std::codecvt<char16_t, char, std::mbstate_t> { };
  51. // https://gcc.gnu.org/ml/libstdc++/2017-11/msg00022.html
  52. streambuf sb;
  53. std::wbuffer_convert<codecvt, char16_t> conv(&sb);
  54. VERIFY( sb.in_avail() == 0 );
  55. char16_t c = conv.sgetc();
  56. VERIFY( c == u'a' );
  57. }
  58. int
  59. main()
  60. {
  61. test01();
  62. test02();
  63. }