This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
[RFC] list::remove vs const& arguments...
- From: Paolo Carlini <pcarlini at suse dot de>
- To: libstdc++ <libstdc++ at gcc dot gnu dot org>
- Cc: Nathan Myers <ncm at cantrip dot org>
- Date: Tue, 14 Sep 2004 11:49:26 +0200
- Subject: [RFC] list::remove vs const& arguments...
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.