[Issue 5071] New: passing value by ref to a function with an inner dynamic closure results in a wrong code
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Mon Oct 18 09:45:45 PDT 2010
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: nobody at puremagic.com
ReportedBy: 2korden at gmail.com
--- Comment #0 from Koroskin Denis <2korden at 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: -------
More information about the Digitalmars-d-bugs
mailing list