[Bug libstdc++/86013] std::vector::shrink_to_fit() could sometimes use realloc()
glisse at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Fri Jun 1 09:03:00 GMT 2018
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86013
--- Comment #5 from Marc Glisse <glisse at gcc dot gnu.org> ---
(In reply to Jan Kratochvil from comment #0)
> Maybe it could even always call realloc() for size reduction of any type of
> objects and just assert the returned pointer did not change.
I can't find anywhere a guarantee that realloc doesn't move stuff when the new
size is smaller than the old.
(In reply to Richard Biener from comment #3)
> I wonder if technically shrink_to_fit() is allowed to elide the shrinking?
> And yes, I'm equally shocked about the need to copy!
What would be the point of shrink_to_fit() otherwise? It was created as a nicer
alternative for people who were copying to a new temporary vector and swapping
them.
More information about the Gcc-bugs
mailing list