From 498342f491d57148564486ddff73767ad7065db8 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= <sebastien@dynare.org>
Date: Tue, 18 Mar 2025 15:17:28 +0100
Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fix=20handling=20of=20model=20lo?=
 =?UTF-8?q?cal=20variable=20in=20DataTree=20copy=20constructor?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Implement the fix that is already present in assignment operator (in particular
for dynare#1782).

(cherry picked from commit fff9ffc52d2066e5948a9a884dcedc58a8ab312e)
---
 src/DataTree.cc | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/src/DataTree.cc b/src/DataTree.cc
index 49303d68..9c3d1899 100644
--- a/src/DataTree.cc
+++ b/src/DataTree.cc
@@ -66,13 +66,14 @@ DataTree::DataTree(const DataTree& d) :
   // Constants must be initialized first because they are used in some Add* methods
   initConstants();
 
+  // See commment in DataTree::operator=() for the rationale
+  for (int symb_id : d.local_variables_vector)
+    local_variables_table[symb_id] = d.local_variables_table.at(symb_id)->clone(*this);
+
   for (const auto& it : d.node_list)
     it->clone(*this);
 
   assert(node_list.size() == d.node_list.size());
-
-  for (const auto& [symb_id, value] : d.local_variables_table)
-    local_variables_table[symb_id] = value->clone(*this);
 }
 
 DataTree&
-- 
GitLab