https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102221
--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> --- (In reply to Giuseppe D'Angelo from comment #2) > Hi, > > Thanks for the analysis! > > That basically allows me to reduce the testcase to something as simple as a > swap: Yes. The actual swaps done by std::sort don't cause the problem, because they use the overload for swapping unique_ptrs, which calls the member function, which doesn't need to create+destroy a local. But the __unguarded_linear_insert function doesn't use swap, and directly creates a local like the generic std::swap does. > I don't think this falls on libstdc++, rather than on the optimizer? Agreed, except that we might (one day) be able to simplify unique_ptr, to help the optimizer do better.