https://gcc.gnu.org/bugzilla/show_bug.cgi?id=127540
--- Comment #5 from Jonathan Wakely <redi at gcc dot gnu.org> ---
OK, thanks.
I think a better fix would be:
--- a/libstdc++-v3/include/debug/safe_iterator.h
+++ b/libstdc++-v3/include/debug/safe_iterator.h
@@ -222,6 +222,7 @@ namespace __gnu_debug
__x._M_detach();
std::swap(base(), __x.base());
_M_attach(__seq);
+ __x._M_version = 0;
}
#endif
@@ -328,6 +329,7 @@ namespace __gnu_debug
__x._M_detach();
__x.base() = _Iterator();
+ __x._M_version = 0;
return *this;
}
#endif
This defangs the assertion on line 307 so that the __x._M_value_initialized()
test is true on a moved-from _Safe_iterator. But it doesn't completely remove
that assertion, so that we still diagnose this case:
#define _GLIBCXX_DEBUG
#include <vector>
int main()
{
std::vector<int>::iterator i;
{
std::vector<int> v{1};
i = v.begin();
}
auto j = std::move(i);
}
If we just remove the assertion then this isn't diagnosed.
We would also need to remove the assertions in the copy and move constructors
and copy and move assignments, because the example in comment 2 should be valid
for copies as well as for moves, and for assignments.
So I think the fix is just to say that for our safe iterators, the moved-from
state is equivalent to the value-initialized state. And so we should set
_M_version=0 on move.