From da1d78a3c2f20de6b43c88839627573cec2fda17 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Sat, 5 May 2018 07:57:37 +1000 Subject: [PATCH] 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. --- src/commands.cc | 9 ++++++++- src/utils.hh | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/commands.cc b/src/commands.cc index 6907344b..089db654 100644 --- a/src/commands.cc +++ b/src/commands.cc @@ -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>()] { - 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 saved_registers; diff --git a/src/utils.hh b/src/utils.hh index 23afdeb1..f21be9c1 100644 --- a/src/utils.hh +++ b/src/utils.hh @@ -73,7 +73,7 @@ public: { other.m_valid = false; } [[gnu::always_inline]] - ~OnScopeEnd() { if (m_valid) m_func(); } + ~OnScopeEnd() noexcept(noexcept(std::declval()())) { if (m_valid) m_func(); } private: bool m_valid;