------- Comment #5 from jwakely dot gcc at gmail dot com  2010-03-01 15:05 
-------
OK, I'm back and have had time to look at this.  I vaguely remember noticing
that the assignment and the deleter invocation happened in the wrong order in
our implementation, but I must have forgotten about it as I don't have any
uncommitted change (or even a comment) in my working copy.

The suggested change is still incorrect: the wrong condition is checked. The
deleter must be invoked when old_p != NULL, rather than when old_p != p.
Consider:

unique_ptr<int> p1;
p1.reset(new int);

The deleter should not be invoked by the call to reset, because old_p ==
nullptr.

Another case:

  unique_ptr<int> p(new int);
  p.reset(p.get());
  p.release();

This should not leak, but with the suggested change it will, because the
deleter will not get invoked.

A better implementation would be (untested):

      void
      reset(pointer __p = pointer())
      {
        pointer __old = get();
        std::get<0>(_M_t) = __p;
        if (__old != 0)
          std::get<1>(_M_t)(__old);
      }


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43183

Reply via email to