called from within the dtor, this may otherwise cause UB (fixes #7).main
| { | { | ||||
| if( m_execute_on_destruction == true ) | if( m_execute_on_destruction == true ) | ||||
| { | { | ||||
| m_deleter(); | |||||
| callDeleterSafe(); | |||||
| } | } | ||||
| } | } | ||||
| private: | private: | ||||
| void callDeleterSafe() noexcept | |||||
| { | |||||
| try | |||||
| { | |||||
| m_deleter(); | |||||
| } | |||||
| catch( ... ) { /* Empty */ } | |||||
| } | |||||
| Deleter m_deleter; | Deleter m_deleter; | ||||
| bool m_execute_on_destruction; | bool m_execute_on_destruction; | ||||
| }; | }; |
| REQUIRE(executed == false); | REQUIRE(executed == false); | ||||
| } | } | ||||
| TEST_CASE("no exception propagation from deleter", "[ScopeGuard]") | |||||
| { | |||||
| REQUIRE_NOTHROW([] { | |||||
| auto guard = sr::scope_guard([] { throw "Don't propagate this!"; }); | |||||
| static_cast<void>(guard); | |||||
| }()); | |||||
| } |