monotone-devel
[Top][All Lists]
Advanced

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

Re: [Monotone-devel] MM with temporaries


From: Christof Petig
Subject: Re: [Monotone-devel] MM with temporaries
Date: Fri, 23 Sep 2005 09:16:36 +0200
User-agent: Mozilla Thunderbird 1.0.6 (X11/20050912)

Nathaniel Smith schrieb:
> I noticed .cvssync got a few lines like:
>     MM(boost::lexical_cast<std::string>(i->time));
> recently.  I'm pretty sure these can't possibly work?

This usage shows a problem: Musings on integer variables are not
possible with the current system.

What about a value storing musing variant? I certainly have use for it.

> 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...
> 
> Distressingly, the compiler gives no warning or anything for this.

The only way I know to make the compiler warn about this is to require a
non const reference. (The usual way to require a non temporary argument
IIRC).

> Anyone know how a way to get the compiler to stop (or a least warn) on
> such things, or alternatively how to make them actually work?  We
> don't want to just unconditionally store a value copy instead of a
> reference, because MM() needs to be very cheap when assertions are not
> hit, and this would make it very slow...

If we manage to copy the value once it is const this would work
transparently (I don't know how to accomplish this, the STL algo
variants e.g. decide by class inheritance, perhaps a similar way is
possible). Is there a gcc internal function or a macro which tells
whether an expression is a lvalue?

   Christof

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

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