[Issue 5541] Disallow escaping of references to stack-allocated memory

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Feb 9 15:21:55 PST 2012


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


timon.gehr at gmx.ch changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
                 CC|                            |timon.gehr at gmx.ch
         Resolution|INVALID                     |


--- Comment #2 from timon.gehr at gmx.ch 2012-02-09 15:21:53 PST ---
This is not about struct literals being lvalues, Walter states this is by
design anyway.
Furthermore, struct literals are certainly allocated on the stack and what
bearophile shows is not valid code.

struct Foo {
    int x;
}
Foo* bar() {
    return &(Foo(1));
}
void qux(ref Foo f,int x){
    writeln(f.x);
}
void main() {
    Foo* x = bar();
    qux(*bar(),2);
}

compiling and running for 32 bit prints garbage, and looking at the disassembly
shows that the literal is indeed allocated on the stack.

-- 
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