瀏覽代碼

Dtor of scope_exit updated. It is now no longer guarding against

exceptions thrown by the deleter (#28), furthermore it's noexcept
now.
main
offa 7 年之前
父節點
當前提交
9697cfefe9
共有 2 個檔案被更改,包括 2 行新增19 行删除
  1. +2
    -12
      include/scope_exit.h
  2. +0
    -7
      test/ScopeExitTest.cpp

+ 2
- 12
include/scope_exit.h 查看文件

other.release(); other.release();
} }


~scope_exit()
~scope_exit() noexcept(true)
{ {
if( m_execute_on_destruction == true ) if( m_execute_on_destruction == true )
{ {
call_deleter_safe();
m_deleter();
} }
} }




private: private:


void call_deleter_safe() noexcept
{
try
{
m_deleter();
}
catch( ... ) { /* Empty */ }
}


Deleter m_deleter; Deleter m_deleter;
bool m_execute_on_destruction; bool m_execute_on_destruction;
}; };

+ 0
- 7
test/ScopeExitTest.cpp 查看文件

static_cast<void>(guard); static_cast<void>(guard);
} }


TEST_CASE("no exception propagation from deleter", "[ScopeExit]")
{
REQUIRE_NOTHROW([] {
auto guard = sr::make_scope_exit([] { throw std::exception{}; });
static_cast<void>(guard);
}());
}

Loading…
取消
儲存