This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug libstdc++/58159] unique_ptr::reset should have debug assertion for "self-reset"
- From: "gromer at google dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Wed, 17 Sep 2014 20:57:24 +0000
- Subject: [Bug libstdc++/58159] unique_ptr::reset should have debug assertion for "self-reset"
- Auto-submitted: auto-generated
- References: <bug-58159-4 at http dot gcc dot gnu dot org/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=58159
--- Comment #6 from Geoff Romer <gromer at google dot com> ---
A Chromium maintainer privately pointed out a use case that would be thwarted
by a check like this: basically, unique_ptr is used to hold pointers from a
legacy API, using a custom deleter that decrements a reference count rather
than actually destroying the object. If the legacy API returns the same pointer
from multiple calls, this can lead to reset() being legitimately called with a
pointer equal to the stored value.
So on reflection, I agree this can only be done for default_delete.