Do not let exception propagate out of register restoring lambda

It is called during a std::vector destruction, which is noexcept,
leading to terminate being called.
This commit is contained in:
Maxime Coste 2018-05-05 07:57:37 +10:00
parent 7325ad216c
commit da1d78a3c2
2 changed files with 9 additions and 2 deletions

View File

@ -1563,7 +1563,14 @@ void context_wrap(const ParametersParser& parser, Context& context, Func func)
auto& register_manager = RegisterManager::instance();
auto make_register_restorer = [&](char c) {
return on_scope_end([&, c, save=register_manager[c].get(context) | gather<Vector<String>>()] {
RegisterManager::instance()[c].set(context, save);
try
{
RegisterManager::instance()[c].set(context, save);
}
catch (runtime_error& err)
{
write_to_debug_buffer(format("failed to restore register '{}': {}", c, err.what()));
}
});
};
Vector<decltype(make_register_restorer(0))> saved_registers;

View File

@ -73,7 +73,7 @@ public:
{ other.m_valid = false; }
[[gnu::always_inline]]
~OnScopeEnd() { if (m_valid) m_func(); }
~OnScopeEnd() noexcept(noexcept(std::declval<T>()())) { if (m_valid) m_func(); }
private:
bool m_valid;