Merge -r 127928:132243 from trunk
[official-gcc.git] / libstdc++-v3 / testsuite / 22_locale / global_templates / standard_facet_hierarchies.cc
blob6b157e35aeca29370e4222eb159ccc1b1f95cbeb
1 // Copyright (C) 2007, 2008 Free Software Foundation
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 2, or (at your option)
7 // 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.
14 // You should have received a copy of the GNU General Public License along
15 // with this library; see the file COPYING. If not, write to the Free
16 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
17 // USA.
19 #include <string>
20 #include <locale>
21 #include <testsuite_hooks.h>
23 // Based on Langer Kreft "Standard C++ IOStreams and Locales" p 316-318
24 // PR libstdc++/30127
25 // PR libstdc++/34449
26 int main()
28 bool test __attribute__((unused)) = true;
30 using std::locale;
31 using std::has_facet;
32 using std::use_facet;
33 typedef std::ctype<char> base_facet;
34 typedef std::ctype_byname<char> derived_facet;
36 locale loc_c = locale::classic();
37 locale loc_base = loc_c;
38 locale loc_derived(loc_c, new derived_facet("C"));
40 // Standard base facet.
41 VERIFY( has_facet<base_facet>(loc_c) );
42 VERIFY( has_facet<base_facet>(loc_base) );
43 VERIFY( has_facet<base_facet>(loc_derived) );
45 // Standard derived facet.
46 VERIFY( !has_facet<derived_facet>(loc_c) );
47 VERIFY( !has_facet<derived_facet>(loc_base) );
48 VERIFY( has_facet<derived_facet>(loc_derived) );
51 // 1
52 try
54 if (has_facet<derived_facet>(loc_base))
56 use_facet<derived_facet>(loc_base).widen('k');
57 VERIFY( true );
60 catch (...)
62 // Expect no exception.
63 VERIFY( true );
66 // 2
67 try
69 if (has_facet<base_facet>(loc_derived))
70 use_facet<base_facet>(loc_derived).widen('k');
71 else
72 VERIFY( true );
74 catch (...)
76 // Expect no exception.
77 VERIFY( true );
80 return 0;