monotone-devel
[Top][All Lists]
Advanced

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

[Monotone-devel] Re: MM with temporaries


From: Steven E. Harris
Subject: [Monotone-devel] Re: MM with temporaries
Date: Thu, 22 Sep 2005 14:01:03 -0700
User-agent: Gnus/5.110004 (No Gnus v0.4) XEmacs/21.4.13 (cygwin32)

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.

You may want to read up on Alexandrescu's original ScopeGuard article¹
to see deliberate (mis)use of this rule.


Footnotes: 
¹ http://www.cuj.com/documents/s=8000/cujcexp1812alexandr/alexandr.htm

-- 
Steven E. Harris





reply via email to

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