1.cc 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. // 2000-09-11 Benjamin Kosnik <bkoz@redhat.com>
  2. // Copyright (C) 2000-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. // 22.1.2 locale globals [lib.locale.global.templates]
  17. #include <cwchar> // for mbstate_t
  18. #include <locale>
  19. #include <typeinfo>
  20. #include <testsuite_hooks.h>
  21. typedef std::codecvt<char, char, std::mbstate_t> ccodecvt;
  22. class gnu_codecvt: public ccodecvt { };
  23. void test01()
  24. {
  25. using namespace std;
  26. // construct a locale object with the C facet
  27. const locale& cloc = locale::classic();
  28. // sanity check the constructed locale has the normal facet
  29. VERIFY( has_facet<ccodecvt>(cloc) );
  30. // construct a locale object with the specialized facet.
  31. locale loc(locale::classic(), new gnu_codecvt);
  32. // sanity check the constructed locale has the specialized facet.
  33. VERIFY( has_facet<gnu_codecvt>(loc) );
  34. try
  35. { const ccodecvt& cvt01 __attribute__((unused)) = use_facet<ccodecvt>(cloc); }
  36. catch(...)
  37. { VERIFY( false ); }
  38. try
  39. { const gnu_codecvt& cvt02 __attribute__((unused)) = use_facet<gnu_codecvt>(loc); }
  40. catch(...)
  41. { VERIFY( false ); }
  42. try
  43. { const ccodecvt& cvt03 __attribute__((unused)) = use_facet<gnu_codecvt>(cloc); }
  44. catch(bad_cast& obj)
  45. { VERIFY( true ); }
  46. catch(...)
  47. { VERIFY( false ); }
  48. }
  49. int main ()
  50. {
  51. test01();
  52. return 0;
  53. }