facet.pass.cpp revision f5256e16dfc425c1d466f6308d4026d529ce9e0b
1//===----------------------------------------------------------------------===//
2//
3//                     The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10// <locale>
11
12// class locale::facet
13// {
14// protected:
15//     explicit facet(size_t refs = 0);
16//     virtual ~facet();
17//     facet(const facet&) = delete;
18//     void operator=(const facet&) = delete;
19// };
20
21// This test isn't portable
22
23#include <locale>
24#include <cassert>
25
26struct my_facet
27    : public std::locale::facet
28{
29    static int count;
30    my_facet(unsigned refs = 0)
31        : std::locale::facet(refs)
32        {++count;}
33
34    ~my_facet() {--count;}
35};
36
37int my_facet::count = 0;
38
39int main()
40{
41    my_facet* f = new my_facet;
42    f->__add_shared();
43    assert(my_facet::count == 1);
44    f->__release_shared();
45    assert(my_facet::count == 0);
46    f = new my_facet(1);
47    f->__add_shared();
48    assert(my_facet::count == 1);
49    f->__release_shared();
50    assert(my_facet::count == 1);
51    f->__release_shared();
52    assert(my_facet::count == 0);
53}
54