diff --git a/src/Scope.h b/src/Scope.h index 83772e1b9f..ea96422c2c 100644 --- a/src/Scope.h +++ b/src/Scope.h @@ -31,7 +31,15 @@ public: } template - void Insert(N &&name, ID* id) { local[std::forward(name)] = id; } + void Insert(N &&name, ID* id) + { + auto i = local.emplace(std::forward(name), id); + if ( ! i.second ) + { + Unref(i.first->second); + i.first->second = id; + } + } template ID* Remove(N &&name)