1 // { dg-require-namedlocale "" }
3 // 2000-08-31 Benjamin Kosnik <bkoz@redhat.com>
5 // Copyright (C) 2000, 2002, 2003, 2005 Free Software Foundation
7 // This file is part of the GNU ISO C++ Library. This library is free
8 // software; you can redistribute it and/or modify it under the
9 // terms of the GNU General Public License as published by the
10 // Free Software Foundation; either version 2, or (at your option)
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // You should have received a copy of the GNU General Public License along
19 // with this library; see the file COPYING. If not, write to the Free
20 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
23 // 22.1.1.1.2 - class locale::facet [lib.locale.facet]
25 #include <cwchar> // for mbstate_t
31 #include <testsuite_hooks.h>
33 // Static counter for use in checking ctors/dtors.
34 static std::size_t counter
;
36 class surf
: public std::locale::facet
39 static std::locale::id id
;
40 surf(size_t refs
= 0): std::locale::facet(refs
) { ++counter
; }
41 ~surf() { --counter
; }
44 std::locale::id
surf::id
;
46 typedef surf facet_type
;
51 bool test
__attribute__((unused
)) = true;
53 // 1: Destroyed when out of scope.
54 VERIFY( counter
== 0 );
56 locale
loc01(locale::classic(), new facet_type
);
57 VERIFY( counter
== 1 );
59 VERIFY( counter
== 0 );
61 // 2: Not destroyed when out of scope, deliberately leaked.
62 VERIFY( counter
== 0 );
64 // Default refs argument is zero.
65 locale
loc02(locale::classic(), new facet_type(1));
66 VERIFY( counter
== 1 );
68 VERIFY( counter
== 1 );
74 facet_type
* f
= new facet_type(numeric_limits
<size_t>::max());
75 VERIFY( counter
== 1 );
77 locale
loc01(locale::classic(), f
);
79 // Add another reference...
80 locale
loc02(locale::classic(), f
);
82 VERIFY( counter
== 1 );
85 // 4: Named locale should destroy facets when it goes out of scope.
86 // Not quite sure how to test for this w/o valgrind at the moment.
88 locale loc03
= locale("es_MX");