There are no comparison operators for SparseMatrix::InnerIterator, but there is a non-explicit (which maybe should be explicit!) conversion operator to bool. As a result, a naïve attempt to compare these iterators compiles, but is subtly broken because the result tests if both iterators are *valid*, not if both iterators are the *same*. This caused a program crash in our application (MapGUI) due to use of such iterators (via [1]) in an emulated ranged-based for loop ([2]) which compares a 'current' and 'previous' iterator in order to implement a do-once loop (used to declare a local variable in the init block of the for loop). [1] https://github.com/Kitware/vital/blob/master/vital/util/enumerate_matrix.h [2] https://github.com/Kitware/vital/blob/master/vital/vital_foreach.h (see the not-C++11, not-boost implementation) Please implement == and != operators for this iterator, as are expected to be defined for iterators.
I can work around this issue because the loop comparison is calling the operator== of a wrapping iterator, and I can add a work-around to that implementation. In general, however, there is a nasty and subtle behavior with the current implementation: InnerIterator iter = ...; // precondition: iter is valid auto sentinel = iter; for (auto value = *iter; iter == sentinel; ++iter) { ... } From casual examination, the above loop should execute exactly once. This is not the actual behavior. (This is a simplification of the logic that's causing us trouble.)
-- GitLab Migration Automatic Message -- This bug has been migrated to gitlab.com's GitLab instance and has been closed from further activity. You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.com/libeigen/eigen/issues/1192.