https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109442
--- Comment #32 from Jan Hubicka <hubicka at gcc dot gnu.org> --- thanks. I think codegen should be fine, so I will commit the patch so we get it tested by LNT. We may get bit better here. Applying the reverted _M_invariant patch (r14-1452-gfb409a15d9babc) gets me 133 bad_alloc and 128 bad_array_new_length calls. I will try a version that adds the extra size <= capacity check to capacity() that I think is used less. Also it seems at some places size is computed directly instead of calling size function which may be reason for remaining bad allocs.