Re: Does std::unique_ptr support self-reset?
Am 12.08.2013 09:18, schrieb Greg Marr:
On Sunday, August 11, 2013 6:10:02 PM UTC-4, Daniel Kr?gler wrote:
At least in VS2010 and 2012, unique_ptr::reset checks for setting
the same pointer and ignores it.
This is indeed a non-conforming C++11 implementation, because
those effects were intentionally changed as of
I guess the libstdc++ implementation is non-conforming too.
void
reset(pointer __p = pointer()) noexcept
{
using std::swap;
swap(std::get<0>(_M_t), __p);
if (__p != pointer())
get_deleter()(__p);
}
(though the array specialization matches the standard)
http://gcc.gnu.org/viewcvs/gcc/trunk/libstdc%2B%2B-v3/include/bits/unique_pt
r.h?view=markup
I read the defect report, but I still can't understand why someone would
explicitly change from specifying that p.reset(p.get()) was safe to it
resulting in undefined behavior (dangling pointer immediately and then a
double-delete in the unique_ptr destructor),
I don't see why unique_ptr should support
p.reset(p.get());
reset is supposed to take a nullptr or pointer to an object that's not
already owned by someone else. So, if you invoke reset with an address
of some object that another (or the same) unique_ptr instance already
owns, you did something wrong.
Can you come with with an example that relies on a self-reset-test but
is not considered broken by others?
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]