https://gcc.gnu.org/bugzilla/show_bug.cgi?id=127540
--- Comment #10 from Jonathan Wakely <redi at gcc dot gnu.org> --- (In reply to François Dumont from comment #9) > (In reply to Jonathan Wakely from comment #8) > > (In reply to François Dumont from comment #7) > > > What about fixing it this way ? > > > > Would this mean that a copy of a moved-from iterator would be in the > > value-initialized state, but the moved-from iterator itself would not be? > > > > Yes, indeed. > > I'm seeing things more in terms of singularity. With this approach a > singular iterator would give a singular iterator after copy or move. A value-initialized iterator is still singular, so my approach also gives that guarantee. I like the fact that my approach gives a simple guarantee that is easy to reason about: a moved-from iterator is returned to the value-initialized state. This is the same guarantee given by e.g. std::unique_ptr and std::shared_ptr. I'm unsure how to describe the mental model for your approach. A moved-from iterator is in a singular (not value-initialized) state, but copying it produces an iterator in the value-initialized state. That does have the advantage that comparing a moved-from iterator to any other iterator would assert, which is allowed by the standard and should catch some bugs. My approach doesn't have that property. > With > current code only the assertion prevent a singular iterator to give a valid > iterator on copy. > > Of course it means that a problem would trigger an assertion only when the > iterator is actually used for something. Good, that fixes the bug. Copying them is allowed so should not fail an assertion. > __msg_init_copy_singular or > __msg_copy_singular won't be used anymore. > > > > IMHO to detect that iterator's lifetime hasn't started yet is a compiler's > > > job, not _GLIBCXX_DEBUG mode one. > > > > A nice idea in theory, but impossible in practice because C++ supports > > separate compilation. > > It could at least do it within a Translation Unit, no ? Yes, but that's not very useful in practice. But I agree that debug mode should not attempt to diagnose it.
