http://d.puremagic.com/issues/show_bug.cgi?id=9748
Summary: Wrong scope of templated nested functions in static
foreach
Product: D
Version: D2
Platform: All
OS/Version: All
Status: NEW
Keywords: wrong-code
Severity: normal
Priority: P2
Component: DMD
AssignedTo: [email protected]
ReportedBy: [email protected]
--- Comment #0 from Vladimir Panteleev <[email protected]> 2013-03-18
17:01:51 EET ---
template Tuple(T...) { alias T Tuple; }
void main()
{
foreach (i; Tuple!(1, 2, 3))
{
uint j;
void set()(int n) { j = n; }
set(i);
assert(j==i);
}
}
This fails because the "set" function will always refer to the "j" variable
declared in the first foreach iteration. If you move the "j" declaration
outside the loop, the asserts pass.
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------