[RFC] libstdc++: Leave safe iterators in valid state post-move [PR127540]

Nathan Myers ncm@cantrip.org
Mon Oct 19 14:26:13 GMT 2026


On 10/16/26 10:56 AM, Jonathan Wakely wrote:
> On Fri, 16 Oct 2026 at 15:37, Nathan Myers <ncm@cantrip.org> wrote:
>>
>> (streambuf_iterator uses the default-initialized state as its sentinel
>> value, so that avenue is closed for it.)
>>
>> Iterators are normally passed and returned by value, so a distinct
>> moved-from state lost on copying would be lost very quickly.
>> Why couldn't the moved-from state be carried across copies?
>> I think we would also like to trap comparing the copies.
> 
> We do today, but the way we do it leads to false positives, see the
> examples in PR 127540.
> 
> I think we'd get what you want if we just remove the assertions in the
> copy and move operations. That would allow copying singular iterators,
> including moved-from iterators, but the originals and the copies would
> remain radioactive and not comparable.

If they are "valid", then copying and moving them as-is seems best.
Converting to the default-initialized state already loses the
opportunity to trap at that early point.

-N


More information about the Libstdc++ mailing list