mirror of https://github.com/YosysHQ/yosys.git
63e4114233
An `std::vector<T>::reverse_iterator` stores the `std::vector<T>::iterator` which points to the (forwards-ordered) *following* item. Thus while `vec.rbegin()` dereferences to the final item of `vec`, the iterator it wraps (`vec.rbegin().base()`) is equal to `vec.end()`. In the remove case here, we advance `it` (backwards), erasing the item we just advanced past by grabbing its (pre-increment) base forward-iterator and subtracting 1. The iterator maths here is obviously all OK, but the forward-iterator that `it` wraps post-increment actually points to the item we just removed. That iterator was invalidated by the `erase()` call. That this works anyway is (AFAICT) some combination of luck and/or promises that aren't part of the C++ spec, but MSVC's debug iterator support picks this up. `erase()` returns the new iterator that follows the item just erased, which happens to be the exact one we want our reverse-iterator to wrap for the next loop; we get a fresh iterator to the same base, now without the preceding item. |
||
---|---|---|
.. | ||
Makefile.inc | ||
proc.cc | ||
proc_arst.cc | ||
proc_clean.cc | ||
proc_dff.cc | ||
proc_dlatch.cc | ||
proc_init.cc | ||
proc_memwr.cc | ||
proc_mux.cc | ||
proc_prune.cc | ||
proc_rmdead.cc | ||
proc_rom.cc |