[Issue 5635] New: Code inside 'foreach' cannot modify variable out of its scope in a template function.
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Mon Feb 21 12:16:25 PST 2011
http://d.puremagic.com/issues/show_bug.cgi?id=5635
Summary: Code inside 'foreach' cannot modify variable out of
its scope in a template function.
Product: D
Version: D2
Platform: Other
OS/Version: Mac OS X
Status: NEW
Severity: normal
Priority: P2
Component: DMD
AssignedTo: nobody at puremagic.com
ReportedBy: kennytm at gmail.com
--- Comment #0 from kennytm at gmail.com 2011-02-21 12:13:44 PST ---
The following program should compile:
pure bool foo(R=int)(string x) {
bool result = false;
foreach (dchar d; x)
result = true;
return result;
}
void main () {
foo("hi");
}
But as of v2.052 it raises the errors:
x.d(4): Error: pure nested function '__foreachbody3' cannot access mutable data
'result'
x.d(9): Error: template instance x.foo!(int) error instantiating
If the template parameter (R=int) were removed, the program compiles
successfully. (I think this is related to Issue 3316).
--
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