]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/22_locale/locale/cons/unicode.cc
Use effective-target instead of -std options
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 22_locale / locale / cons / unicode.cc
1 // { dg-require-iconv "ISO-8859-1" }
2 // { dg-do run { target c++11 } }
3
4 // Copyright (C) 2006-2016 Free Software Foundation, Inc.
5 //
6 // This file is part of the GNU ISO C++ Library. This library is free
7 // software; you can redistribute it and/or modify it under the
8 // terms of the GNU General Public License as published by the
9 // Free Software Foundation; either version 3, or (at your option)
10 // any later version.
11
12 // This library is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
16
17 // You should have received a copy of the GNU General Public License along
18 // with this library; see the file COPYING3. If not see
19 // <http://www.gnu.org/licenses/>.
20
21 // 22.1.1.2 locale constructors and destructors [lib.locale.cons]
22
23 #include <cwchar> // for mbstate_t
24 #include <locale>
25 #include <stdexcept>
26 #include <typeinfo>
27 #include <testsuite_hooks.h>
28 #include <ext/codecvt_specializations.h>
29
30 typedef std::codecvt<char, char, std::mbstate_t> c_codecvt;
31
32 #ifdef _GLIBCXX_USE_WCHAR_T
33 typedef std::codecvt<wchar_t, char, std::mbstate_t> w_codecvt;
34 #endif
35
36 #ifdef _GLIBCXX_USE_C99_STDINT_TR1
37 typedef std::codecvt<char16_t, char, std::mbstate_t> u16_codecvt;
38 typedef std::codecvt<char32_t, char, std::mbstate_t> u32_codecvt;
39 #endif
40
41 class gnu_facet: public std::locale::facet
42 {
43 public:
44 static std::locale::id id;
45 };
46
47 std::locale::id gnu_facet::id;
48
49 void test01()
50 {
51 using namespace std;
52 typedef unsigned short int_type;
53 typedef char ext_type;
54 typedef __gnu_cxx::encoding_state state_type;
55 typedef codecvt<int_type, ext_type, state_type> unicode_codecvt;
56
57 bool test __attribute__((unused)) = true;
58
59 // unicode_codecvt
60 locale loc01(locale::classic());
61 locale loc13(locale::classic(), new unicode_codecvt);
62 VERIFY( loc01 != loc13 );
63 VERIFY( loc13.name() == "*" );
64 try
65 {
66 VERIFY( has_facet<c_codecvt>(loc13) );
67 #ifdef _GLIBCXX_USE_WCHAR_T
68 VERIFY( has_facet<w_codecvt>(loc13) );
69 #endif
70 #ifdef _GLIBCXX_USE_C99_STDINT_TR1
71 VERIFY( has_facet<u16_codecvt>(loc13) );
72 VERIFY( has_facet<u32_codecvt>(loc13) );
73 #endif
74 VERIFY( has_facet<unicode_codecvt>(loc13) );
75 }
76 catch(...)
77 { VERIFY( false ); }
78
79 try
80 { use_facet<gnu_facet>(loc13); }
81 catch(bad_cast& obj)
82 { VERIFY( true ); }
83 catch(...)
84 { VERIFY( false ); }
85 }
86
87 int main()
88 {
89 test01();
90 return 0;
91 }