[Issue 3925] Missed escaping reference of a local variable

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Mar 10 12:04:06 PST 2010


http://d.puremagic.com/issues/show_bug.cgi?id=3925


Michel Fortin <michel.fortin at michelf.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |michel.fortin at michelf.com


--- Comment #3 from Michel Fortin <michel.fortin at michelf.com> 2010-03-10 15:04:05 EST ---
(In reply to comment #2)
> I've just been dealing with ref returns in my recent CTFE patch. But I don't
> think it's very complicated.
> As far as I can tell, ref returns are only a problem if a local variable is
> passed as a ref parameter, or if it is a member function of a local struct.
> If either of those is true, it should be considered to potentially be a return
> of a local variable.
> I don't think there's any problem with foo, but bar should generate an error.

This seems fair. There is a similar problem with delegates:

@safe
void delegate() foo(ref int a) {
    return { writeln(a); };
}

@safe
void delegate() bar() {
    int a;
    return foo(a); // leaking reference to a beyound bar's scope
}

It could be solved in the same way.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list