1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 // <locale>
10 
11 // class locale::facet
12 // {
13 // protected:
14 //     explicit facet(size_t refs = 0);
15 //     virtual ~facet();
16 //     facet(const facet&) = delete;
17 //     void operator=(const facet&) = delete;
18 // };
19 
20 // This test isn't portable
21 
22 #include <locale>
23 #include <cassert>
24 
25 #include "test_macros.h"
26 
27 struct my_facet
28     : public std::locale::facet
29 {
30     static int count;
my_facetmy_facet31     my_facet(unsigned refs = 0)
32         : std::locale::facet(refs)
33         {++count;}
34 
~my_facetmy_facet35     ~my_facet() {--count;}
36 };
37 
38 int my_facet::count = 0;
39 
main(int,char **)40 int main(int, char**)
41 {
42     my_facet* f = new my_facet;
43     f->__add_shared();
44     assert(my_facet::count == 1);
45     f->__release_shared();
46     assert(my_facet::count == 0);
47     f = new my_facet(1);
48     f->__add_shared();
49     assert(my_facet::count == 1);
50     f->__release_shared();
51     assert(my_facet::count == 1);
52     f->__release_shared();
53     assert(my_facet::count == 0);
54 
55   return 0;
56 }
57