[RFC] list::remove vs const& arguments...
Paolo Carlini
pcarlini@suse.de
Tue Sep 14 09:47:00 GMT 2004
Hi,
we have got a PR, libstdc++/17012, reporting a memory error (both valgrind
and purify agree) for this pattern of usage:
list<int> var;
var.push_back(0);
...
list<int>::iterator i0 = var.begin();
var.remove(*i0);
skipping any irrelevant detail, the point is of course that the iteration
in list::remove, having removed the first element, then refers to deallocated
memory. In turn, this is due to argument passing by const reference (*).
Now, this is not a completely new issue for the libstdc++ list: we already
briefly touched upon it when discussing the optimization of std::fill: I
clearly remember both Nathan and Martin posting comments.
Is there anything in the standard specific to std::list? Or list::remove?
I couldn't find anything... Is the snippet above actually invoking
implementation defined behavior? Is perfectly legal? Or what, really?
Thanks in advance for any comment,
Paolo.
(*) Many thanks to Chris for the analysis.
More information about the Libstdc++
mailing list