]>
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>
24 # pragma warning(disable: 4512) // assignment operator could not be generated
27 struct my_exception1
{};
28 struct my_exception2
{};
30 class exception_watcher2
32 unsigned int& m_count
;
35 explicit exception_watcher2(unsigned int& count
) : m_count(count
) {}
36 ~exception_watcher2() { m_count
= boost::core::uncaught_exceptions(); }
39 class exception_watcher1
41 unsigned int& m_count1
;
42 unsigned int& m_count2
;
45 exception_watcher1(unsigned int& count1
, unsigned int& count2
) : m_count1(count1
), m_count2(count2
) {}
48 m_count1
= boost::core::uncaught_exceptions();
51 exception_watcher2
watcher2(m_count2
);
52 throw my_exception2();
60 // Tests for uncaught_exceptions when used in nested destructors while an exception propagates
61 void test_in_nested_destructors()
63 const unsigned int root_count
= boost::core::uncaught_exceptions();
65 unsigned int level1_count
= root_count
, level2_count
= root_count
;
68 exception_watcher1
watcher1(level1_count
, level2_count
);
69 throw my_exception1();
75 BOOST_TEST_NE(root_count
, level1_count
);
76 BOOST_TEST_NE(root_count
, level2_count
);
77 BOOST_TEST_NE(level1_count
, level2_count
);
82 test_in_nested_destructors();
84 return boost::report_errors();