Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Bugfix][Support] Fix copy constructor for support::OrderedSet (#17044)
Prior to this commit, the `support::OrderedSet<T>` utility used the default copy constructor and copy assignment, which would copy both the `OrderedSet::elements_` and `OrderedSet::elem_to_iter_` members. While this is the correct behavior for `elements_`, the copy of `elem_to_iter_` would contain references to the original's `element_`, rather than to its own. While `elem_to_iter_` is used in both `OrderedSet::push_back` and `OrderedSet::erase`, the implementation of `OrderedSet::push_back` only depends on the keys used in `elem_to_iter_`, and does not depend on the values stored. As a result, this bug could go undetected for append-only usage, which is the most frequent use of `OrderedSet`. This commit updates `support::OrderedSet` to have an explicit copy constructor and copy assignment. Only the `std::list<T> elements_` member may be copied, while the `elem_to_iter_` must instead be rebuilt.
- Loading branch information