From a415c3fe3898d917a8d55366f8e6ea6a36ec8e53 Mon Sep 17 00:00:00 2001 From: David Bailes Date: Sat, 4 Jul 2020 12:56:42 +0100 Subject: [PATCH] Commit 51b3b0f - minor update Using init capture removes any danger of using the wrong value of MacroReentryCount --- src/BatchCommands.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/BatchCommands.cpp b/src/BatchCommands.cpp index 912004bb2..25411c44a 100644 --- a/src/BatchCommands.cpp +++ b/src/BatchCommands.cpp @@ -969,10 +969,8 @@ bool MacroCommands::ApplyMacro( } // Upon exit of the top level apply, roll back the state if an error occurs. - // This code relies on cleanup2 being defined after cleanup1, so that its - // destructor is run before cleanup1's destructor. - auto cleanup2 = finally([&] { - if (MacroReentryCount == 1 && !res && proj) { + auto cleanup2 = finally([&, macroReentryCount = MacroReentryCount] { + if (macroReentryCount == 1 && !res && proj) { // Macro failed or was cancelled; revert to the previous state ProjectHistory::Get(*proj).RollbackState(); }