[Bug c++/86296] Creating a pointer class for a unique_ptr<>() deleter fails with optimizations
redi at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Mon Jun 25 13:24:00 GMT 2018
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86296
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution|--- |INVALID
--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
The reference returned from your operator* ends up dangling, because it was
obtained from a temporary rvalue pointer.
*safe_fd calls unique_ptr::operator* which does:
typename add_lvalue_reference<element_type>::type
operator*() const
{
__glibcxx_assert(get() != pointer());
return *get();
}
The return value of get() is a temporary, which goes out of scope at the end of
the function. The returned reference is bound to the member of the temporary.
More information about the Gcc-bugs
mailing list