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.

Reply via email to