Commit f6aab98
authored
[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.1 parent 08b32a7 commit f6aab98
1 file changed
+27
-4
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
54 | 54 | | |
55 | 55 | | |
56 | 56 | | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
57 | 76 | | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
| 77 | + | |
| 78 | + | |
62 | 79 | | |
63 | 80 | | |
64 | 81 | | |
| |||
90 | 107 | | |
91 | 108 | | |
92 | 109 | | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
93 | 116 | | |
94 | 117 | | |
95 | 118 | | |
| |||
0 commit comments