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

           Summary: passing value by ref to a function with an inner
                    dynamic closure results in a wrong code
           Product: D
           Version: D2
          Platform: Other
        OS/Version: Windows
            Status: NEW
          Keywords: wrong-code
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nob...@puremagic.com
        ReportedBy: 2kor...@gmail.com


--- Comment #0 from Koroskin Denis <2kor...@gmail.com> 2010-10-18 09:44:59 PDT 
---
Here is a test case:

import std.stdio;

void passObject(ref char c, bool dummy)
{
}

void passClosure(void delegate() dg)
{
}

void test(ref char c, bool dummy = false) {
    writeln("inside c=", c, " (", cast(int)c, ") &c=", &c);

    void closure() {
        passObject(c, dummy);
    }

    passClosure(&closure);
}

void main()
{
    //* Test one (c is on heap)
    char* c = new char;
    *c = 'a';

    writeln("outside c=", *c, " (", cast(int)*c, ") &c=", c);
    test(*c, true);

    /*/ Test two (c is on stack)
    char c = 'a';
    writeln("outside c=", c, " (", cast(int)c, ") &c=", &c);
    test(c);
    //*/
}

Test one output:
outside c=a (97) &c=12B2E40
inside c=  (0) &c=12B0140

Test two output:
outside c=a (97) &c=12FE54
object.Error: Access Violation

Note that passing by pointer instead works fine:

outside c=a (97) &c=582E40
inside c=a (97) &c=582E40

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

Reply via email to