1 //===----------------------------------------------------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 // <locale>
11 
12 // template <class charT> class ctype;
13 
14 // explicit ctype(size_t refs = 0);
15 
16 #include <locale>
17 #include <cassert>
18 
19 template <class C>
20 class my_facet
21     : public std::ctype<C>
22 {
23 public:
24     static int count;
25 
my_facet(std::size_t refs=0)26     explicit my_facet(std::size_t refs = 0)
27         : std::ctype<C>(refs) {++count;}
28 
~my_facet()29     ~my_facet() {--count;}
30 };
31 
32 template <class C> int my_facet<C>::count = 0;
33 
main()34 int main()
35 {
36     {
37         std::locale l(std::locale::classic(), new my_facet<wchar_t>);
38         assert(my_facet<wchar_t>::count == 1);
39     }
40     assert(my_facet<wchar_t>::count == 0);
41     {
42         my_facet<wchar_t> f(1);
43         assert(my_facet<wchar_t>::count == 1);
44         {
45             std::locale l(std::locale::classic(), &f);
46             assert(my_facet<wchar_t>::count == 1);
47         }
48         assert(my_facet<wchar_t>::count == 1);
49     }
50     assert(my_facet<wchar_t>::count == 0);
51 }
52