https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86013
--- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> --- shrink_to_fit is a non-binding request, the implementation is allowed to completely ignore it. But the expected semantics (at least, expected by those who designed the feature) is that it reallocates new storage, copies the elements, and deallocates the old storage. If you don't want that, don't call shrink_to_fit. I don't see how this qualifies as a missed-optimization when doing it is impossible in the general case.