This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]