[cfe-dev] [libc++] Implementation of std::map::erase() in libc++ doesn't match that in libstdc++

Marshall Clow mclow.lists at gmail.com
Fri Apr 11 01:29:59 PDT 2014


On Apr 8, 2014, at 1:47 PM, Alexander Potapenko <glider at google.com> wrote:

> Hi all,
> 
> We've encountered an incompatibility between libc++ and libstdc++: for
> std::map::erase(pos) libstdc++ (and MSVS as well) first removes the
> item from a map (a) and then calls its destructor (b), while libc++
> calls the destructor before changing the map structure.
> 
> This results in a crash described at
> https://code.google.com/p/chromium/issues/detail?id=358707: the item
> that's being erased from the map queries that map in the destructor
> calls some methods for the elements it finds. With libc++ that item
> manages to find itself (in an inconsistent state, since it's in the
> destructor already) and crashes.
> 
> Does the standard specify the order of (a) and (b), or it's incorrect
> to rely on the order provided by some of the libraries?

My belief is that the correct answer is (b).

As far as I can tell, the standard makes no mention of this.
[ map::erase has no special requirements, and the general container requirements don’t say anything. ]

However, libc++’s behavior seems a bit odd to me, too.
I committed revision 206024 to change this.

— Marshall





More information about the cfe-dev mailing list