An important potential change to the language: transitory ref

Michel Fortin michel.fortin at michelf.com
Fri Mar 19 20:52:54 PDT 2010


On 2010-03-19 22:56:59 -0400, Andrei Alexandrescu 
<SeeWebsiteForEmail at erdani.org> said:

> So I was thinking of the following: how about still returning a 
> reference, but define a rule in the language that references can't 
> escape - you can't take their address and squirrel it away; the only 
> thing you can do is use them right on the spot or pass them down to 
> functions.

Can functions return the reference, or a reference to a part of the 
original referenced value? It's safe to do this only in some specific 
contexts, but the compiler already has some difficulty dealing with 
this. See bug 3925:
<http://d.puremagic.com/issues/show_bug.cgi?id=3925>

Another effect is that it should prevent closures from using that 
transitory ref value, since a closure can be leaked... unless we add 
transitory closures. :-)

-- 
Michel Fortin
michel.fortin at michelf.com
http://michelf.com/




More information about the Digitalmars-d mailing list