https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100153
--- Comment #6 from CVS Commits <cvs-commit at gcc dot gnu.org> --- The releases/gcc-11 branch has been updated by Jonathan Wakely <r...@gcc.gnu.org>: https://gcc.gnu.org/g:c04b0f63243d4d474daa66f84874ebf6b9e7b0cd commit r11-9281-gc04b0f63243d4d474daa66f84874ebf6b9e7b0cd Author: Jonathan Wakely <jwak...@redhat.com> Date: Tue Apr 20 16:16:13 2021 +0100 libstdc++: Do not allocate a zero-size vector<bool> [PR 100153] The vector<bool>::shrink_to_fit() implementation will allocate new storage even if the vector is empty. That then leads to the end-of-storage pointer being non-null and equal to the _M_start._M_p pointer, which means that _M_end_addr() has undefined behaviour. The fix is to stop doing a useless zero-sized allocation in shrink_to_fit(), so that _M_start._M_p and _M_end_of_storage are both null after an empty vector shrinks. Signed-off-by: Jonathan Wakely <jwak...@redhat.com> libstdc++-v3/ChangeLog: PR libstdc++/100153 * include/bits/vector.tcc (vector<bool>::_M_shrink_to_fit()): When size() is zero just deallocate and reset. (cherry picked from commit 681707ec28d56494fa61a80c62500724d55f8586)