diff --git a/tests/shared_ptr_test.cc b/tests/shared_ptr_test.cc index 21e8a814bf..5abae77f84 100644 --- a/tests/shared_ptr_test.cc +++ b/tests/shared_ptr_test.cc @@ -26,6 +26,8 @@ #include #include "core/shared_ptr.hh" +struct expected_exception : public std::exception {}; + struct A { static bool destroyed; A() { @@ -93,3 +95,23 @@ BOOST_AUTO_TEST_CASE(test_shared_from_this_called_on_const_object) { auto ptr = make_lw_shared(); ptr->const_method(); } + +BOOST_AUTO_TEST_CASE(test_exception_thrown_from_constructor_is_propagated) { + struct X { + X() { + throw expected_exception(); + } + }; + try { + auto ptr = make_lw_shared(); + BOOST_FAIL("Constructor should have thrown"); + } catch (const expected_exception& e) { + BOOST_MESSAGE("Expected exception caught"); + } + try { + auto ptr = ::make_shared(); + BOOST_FAIL("Constructor should have thrown"); + } catch (const expected_exception& e) { + BOOST_MESSAGE("Expected exception caught"); + } +}