Debian Codegraph @

libstdc++-v3/testsuite/22_locale/locale/cons/12438.cc

raw symbols SCIP
1 // { dg-require-namedlocale "" }
2
3 // Copyright (C) 2003-2025 Free Software Foundation, Inc.
4 //
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 3, or (at your option)
9 // any later version.
10
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15
16 // You should have received a copy of the GNU General Public License along
17 // with this library; see the file COPYING3. If not see
18 // <http://www.gnu.org/licenses/>.
19
20 // 22.1.1.2 locale constructors and destructors [lib.locale.cons]
21
22 #include <locale>
23 #include <stdexcept>
24 #include <cstdlib>
25 #include <testsuite_hooks.h>
26
27 class MyFacet : public std::locale::facet
28 {
29 public:
30 static std::locale::id id;
31 };
32
33 std::locale::id MyFacet::id;
34
35 // libstdc++/12438
36 void test01(int iters)
37 {
38 using namespace std;
39
40 for (int i = 0; i < iters; ++i)
41 {
42 try
43 {
44 locale loc1 = locale::classic();
45 locale loc2 = locale("");
46 VERIFY( !has_facet<MyFacet>(loc2) );
47
48 loc1.combine<MyFacet>(loc2); // { dg-warning "nodiscard" "" { target c++11 } }
49 VERIFY( false );
50 }
51 catch (std::runtime_error&)
52 {
53 }
54 }
55 }
56
57 int main(int argc, char* argv[])
58 {
59 // We leaked ~400-500 bytes/iter.
60 __gnu_test::set_memory_limits(10.0);
61 int iters = 30000;
62
63 if (argc > 1)
64 iters = atoi(argv[1]);
65 if (iters < 1)
66 iters = 1;
67 test01(iters);
68
69 return 0;
70 }