monotone-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Monotone-devel] Re: MM with temporaries


From: Nathaniel Smith
Subject: Re: [Monotone-devel] Re: MM with temporaries
Date: Fri, 23 Sep 2005 01:47:29 -0700
User-agent: Mutt/1.5.9i

On Thu, Sep 22, 2005 at 02:01:03PM -0700, Steven E. Harris wrote:
> Nathaniel Smith <address@hidden> writes:
> 
> > MM() ends up passing its argument to Musing(), which takes a const
> > reference argument and stashes it in a member variable const
> > reference.  Then, if an assertion triggers, it prints out the value
> > of that member variable.  In this case, it seems that will point to
> > a already-deleted temporary, and we'll crash or something...
> 
> Binding a const reference to a temporary pins the temporary's lifetime
> to the remainder of the reference's lifetime, per ISO/IEC
> 14882:1998(E) Section 12.2 Footnote 5. So long as you don't hang on to
> that reference for "too long", you're fine.

I don't quite see this.  Quoting the above note 5:

  The second context [in which temporaries are destroyed at a
  different point than the end of the full-expression] is when a
  reference is bound to a temporary. The temporary to which the
  reference is bound or the temporary that is the complete object to a
  subobject of which the temporary is bound persists for the lifetime
  of the reference except as specified below. A temporary bound to a
  reference member in a constructor's ctor-initializer (12.6.2)
  persists until the constructor exits. ...

That last part doesn't sound happy-making to me.  IIUC, we have a
temporary bound to a reference member, but we need it to persist until
the object is destructed, which is much longer than "until the
constructor exits"...

This section is extremely opaque to me, though...

-- Nathaniel

-- 
Eternity is very long, especially towards the end.
  -- Woody Allen




reply via email to

[Prev in Thread] Current Thread [Next in Thread]