Question about RAII.

Jarrett Billingsley kb3ctd2 at yahoo.com
Tue Jul 4 17:33:22 PDT 2006


<Robert.Atkinson at NOSPAM.gmail.com.NOSPAM> wrote in message 
news:e8dtj3$2dc8$1 at digitaldaemon.com...

> Couldn't the compiler detect this and throw an compile-error?  From simple
> inspection it seems to be a pretty easy addition to the compiler, the 
> syntax is
> already quite clear.

You'll notice the auto reference is being assigned to a non-auto reference, 
which makes it all but impossible to detect.  What if it were stuck into an 
array?  What if the auto ref were passed into a function and then returned 
as non-auto?  What if..?

If you try to directly return an auto reference, the compiler will gladly 
whine:

class Foo{}

Foo foo()
{
 auto Foo f = new Foo;
 return f;
}

dtest.d(781): escaping reference to auto local f 





More information about the Digitalmars-d mailing list