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

--- Comment #0 from Koroskin Denis <> 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);


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 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:
------- You are receiving this mail because: -------

Reply via email to