https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104547
--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> --- For this TU with three functions, clang generates good code: #include <vector> void shrink_pop(std::vector<int>& v, std::size_t n) { while (n--) v.pop_back(); } void shrink_assume(std::vector<int>& v, std::size_t n) { if (v.size() < n) __builtin_unreachable(); v.resize(v.size() - n); } void shrink_min(std::vector<int>& v, std::size_t n) { v.resize(std::min<std::size_t>(v.size(), n)); } Clang removes the unreachable __throw_length_error, doesn't explode if the type is size_t, and doesn't keep the unused _M_default_append instantiation.