]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/18_support/uncaught_exceptions/uncaught_exceptions.cc
1 // Copyright (C) 2015-2021 Free Software Foundation, Inc.
3 // This file is part of the GNU ISO C++ Library. This library is free
4 // software; you can redistribute it and/or modify it under the
5 // terms of the GNU General Public License as published by the
6 // Free Software Foundation; either version 3, or (at your option)
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License along
15 // with this library; see the file COPYING3. If not see
16 // <http://www.gnu.org/licenses/>.
18 // { dg-options "-std=gnu++17" }
19 // { dg-do run { target c++17 } }
23 #include <testsuite_hooks.h>
25 #ifndef __cpp_lib_uncaught_exceptions
26 # error "Feature-test macro for uncaught_exceptions missing"
27 #elif __cpp_lib_uncaught_exceptions != 201411
28 # error "Feature-test macro for uncaught_exceptions has wrong value"
31 struct UncaughtVerifier
33 int expected_count_
= 0;
34 UncaughtVerifier(int expected_count
) : expected_count_(expected_count
) {}
37 VERIFY(std::uncaught_exceptions() == expected_count_
);
45 Transaction(bool& result
)
46 : initial_count_(std::uncaught_exceptions()),
50 if (std::uncaught_exceptions() != initial_count_
) {
59 UncaughtVerifier uv
{0};
61 UncaughtVerifier uv
{0};
68 UncaughtVerifier uv
{1};
71 UncaughtVerifier uv
{0};
80 UncaughtVerifier uv_
{1};
81 ~Wrap() {try {UncaughtVerifier uv2
{2}; throw 0;} catch(...) {}}
86 UncaughtVerifier uv
{0};
94 Transaction t
{result
};
104 Transaction t
{result
};
119 Wrap(bool& result
) : result_(result
) {}
122 Transaction t
{result_
};
125 Transaction t
{result
};
142 Wrap(bool& result
) : result_(result
) {}
146 Transaction t
{result_
};
151 Transaction t
{result
};