Is return by ref really @safe?

Walter Bright newshound1 at digitalmars.com
Fri Mar 12 20:41:53 PST 2010


Michel Fortin wrote:
> This compiles, but should it?
> 
> @safe
> ref int foo(ref int a) {
>     return a;
> }
> 
> @safe
> ref int bar() {
>     int a;
>     return foo(a); // leaking reference to a beyond bar's scope
> }

No.



More information about the Digitalmars-d mailing list