https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71945
--- Comment #6 from Jonathan Wakely <redi at gcc dot gnu.org> --- Simpler reproducer which fails the assertion with trunk when the ref count overflows to INT_MIN, but which passes with my local patches: #include <memory> #include <cassert> #include <climits> int main() { std::shared_ptr<int> p(new int(0)); std::shared_ptr<int> p2; long count = p.use_count(); while (count < (long)(UINT_MAX)) { new (&p2) std::shared_ptr<int>(p); ++count; assert(p.use_count() == count); } return *p; } And if I change it to make one more copy: while (count < (long)(UINT_MAX + 1L)) Then the counter no longer overflows, we trap instead: Illegal instruction (core dumped)