]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/core/test/uncaught_exceptions_np.cpp
2 * Copyright Andrey Semashev 2018.
3 * Distributed under the Boost Software License, Version 1.0.
4 * (See accompanying file LICENSE_1_0.txt or copy at
5 * https://www.boost.org/LICENSE_1_0.txt)
8 * \file uncaught_exceptions_np.cpp
9 * \author Andrey Semashev
12 * \brief This file contains tests for the uncaught_exceptions function.
14 * This file contains checks that are compiler specific and not quite portable or require C++17.
17 #include <boost/core/uncaught_exceptions.hpp>
19 #if !defined(BOOST_CORE_UNCAUGHT_EXCEPTIONS_EMULATED)
21 #include <boost/core/lightweight_test.hpp>
23 struct my_exception1
{};
24 struct my_exception2
{};
26 class exception_watcher2
28 unsigned int& m_count
;
31 explicit exception_watcher2(unsigned int& count
) : m_count(count
) {}
32 ~exception_watcher2() { m_count
= boost::core::uncaught_exceptions(); }
35 class exception_watcher1
37 unsigned int& m_count1
;
38 unsigned int& m_count2
;
41 exception_watcher1(unsigned int& count1
, unsigned int& count2
) : m_count1(count1
), m_count2(count2
) {}
44 m_count1
= boost::core::uncaught_exceptions();
47 exception_watcher2
watcher2(m_count2
);
48 throw my_exception2();
56 // Tests for uncaught_exceptions when used in nested destructors while an exception propagates
57 void test_in_nested_destructors()
59 const unsigned int root_count
= boost::core::uncaught_exceptions();
61 unsigned int level1_count
= root_count
, level2_count
= root_count
;
64 exception_watcher1
watcher1(level1_count
, level2_count
);
65 throw my_exception1();
71 BOOST_TEST_NE(root_count
, level1_count
);
72 BOOST_TEST_NE(root_count
, level2_count
);
73 BOOST_TEST_NE(level1_count
, level2_count
);
78 test_in_nested_destructors();
80 return boost::report_errors();