Fix use of std::unordered_map::insert() as pointed out by Nathaniel Wesley Filardo in GitHup Pull Request #8999

This commit is contained in:
Edgar Fuß 2021-10-05 16:51:32 +02:00 committed by Alexander A. Klimov
parent 5bba609e60
commit 20d7e1b5e6
1 changed files with 5 additions and 2 deletions

View File

@ -93,10 +93,13 @@ bool Checkable::IsReachable(DependencyType dt, Dependency::Ptr *failedDependency
// tentatively mark this dependency group as failed unless it is already marked;
// so it either passed before (don't overwrite) or already failed (so don't care)
if (violated.find(redundancy_group) == violated.end())
violated.insert(std::make_pair(redundancy_group, dep));
// note that std::unordered_map::insert() will not overwrite an existing entry
violated.insert(std::make_pair(redundancy_group, dep));
} else if (!redundancy_group.empty()) {
// definitely mark this dependency group as passed
// as std::unordered_map::insert() will not overwrite an existing entry, erase it first
// in C++17, one could use std::unorderer_map::insert_or_assign() instead
violated.erase(redundancy_group);
violated.insert(std::make_pair(redundancy_group, nullptr));
}
}