https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112335

            Bug ID: 112335
           Summary: missed optimization on reset and assign unique_ptr
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: federico at kircheis dot it
  Target Milestone: ---

Given following snippet

----
#include <memory>

struct s{
    s();
    ~s() noexcept;
};



void bar1(std::unique_ptr<s>& ps1, std::unique_ptr<s>& ps2){
    ps1.reset();
    ps1 = std::move(ps2);
}

void bar2(std::unique_ptr<s>& ps1, std::unique_ptr<s>& ps2){
    ps1 = std::move(ps2);
}
----

If I am not mistaken, bar1 and bar2 should have exactly the same behavior, but
on https://godbolt.org/z/q4nKsPq7z it is possible to see that the generated
code differs.

Reply via email to