[Issue 9748] New: Wrong scope of templated nested functions in static foreach

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Mar 18 08:01:52 PDT 2013


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: nobody at puremagic.com
        ReportedBy: thecybershadow at gmail.com


--- Comment #0 from Vladimir Panteleev <thecybershadow at gmail.com> 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: -------


More information about the Digitalmars-d-bugs mailing list