[RFC] unordered container local_iterator invalidation

François Dumont frs.dumont@gmail.com
Sat May 2 21:18:18 GMT 2026


I've eventually considered that _GLIBCXX_DEBUG invalidation was correct 
and so adapted the hashtable fancy pointer PR to match this.

I'll renew the patch soon.

François


On 4/16/26 19:39, François Dumont wrote:
> Hi
>
> I've been a little bit puzzled by the code in 
> _Safe_unordered_container::_M_invalidate_all regarding local_iterator 
> invalidation:
>
>     auto __local_end = _M_cont()._M_base().cend(0);
>     _M_invalidate_local_if(
>       [__local_end](decltype(__local_end) __it)
>       { return __it != __local_end; },
>       sentry);
>
> Why taking arbitrarily bucket 0 as local_iterator end iterator to 
> avoid when invalidating ?
>
> Luckily all cend of any bucket will give a local_iterator with _M_cur 
> node being nullptr and local_iterator, as iterator, only compares this 
> node pointer for equality.
>
> The end result is that, as shown by the attached test case, the end 
> local_iterator are never invalidated on a clear.
>
> Is it clearly what the Standard is saying ? I would find it more 
> natural all local_iterator to be invalidated, no ?
>
> François


More information about the Libstdc++ mailing list