Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libcxx / test / std / localization / locales / locale.global.templates / use_facet.pass.cpp
blobf79317ff9ed0f41931064065936217c98752737e
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 //===----------------------------------------------------------------------===//
9 // <locale>
11 // template <class Facet> const Facet& use_facet(const locale& loc);
13 #include <locale>
14 #include <cassert>
15 #include <typeinfo>
17 #include "test_macros.h"
19 int facet_count = 0;
21 struct my_facet
22 : public std::locale::facet
24 static std::locale::id id;
26 bool im_alive;
28 my_facet() : im_alive(true) {++facet_count;}
29 ~my_facet() {im_alive = false; --facet_count;}
32 std::locale::id my_facet::id;
34 int main(int, char**)
36 #ifndef TEST_HAS_NO_EXCEPTIONS
37 try
39 const my_facet& f = std::use_facet<my_facet>(std::locale());
40 ((void)f); // Prevent unused warning
41 assert(false);
43 catch (std::bad_cast&)
46 #endif
47 const my_facet* fp = 0;
49 std::locale loc(std::locale(), new my_facet);
50 const my_facet& f = std::use_facet<my_facet>(loc);
51 assert(f.im_alive);
52 fp = &f;
53 assert(fp->im_alive);
54 assert(facet_count == 1);
56 assert(facet_count == 0);
58 return 0;