www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 6141] New: Bad code with ref-foreach and closures

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6141

           Summary: Bad code with ref-foreach and closures
           Product: D
           Version: D2
          Platform: x86
        OS/Version: Windows
            Status: NEW
          Keywords: wrong-code
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: thecybershadow gmail.com


--- Comment #0 from Vladimir Panteleev <thecybershadow gmail.com> 2011-06-10
02:18:34 PDT ---
void takeADelegate(void delegate()) {}

void main()
{
    auto items = new int[1];
    items[0] = 17;
    foreach (ref item; items)
    {
        // both asserts fail
        assert(item == 17);
        assert(&item == items.ptr);

        takeADelegate({
            auto x = &item;
        });
    }
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 10 2011
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6141


Vladimir Panteleev <thecybershadow gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |critical


--- Comment #1 from Vladimir Panteleev <thecybershadow gmail.com> 2011-11-01
19:00:36 PDT ---
Hit this again. Raising priority, since it causes "mysterious crashes".

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 01 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6141


Denis <verylonglogin.reg gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |verylonglogin.reg gmail.com


--- Comment #2 from Denis <verylonglogin.reg gmail.com> 2012-04-22 17:21:39 MSD
---
Looks like the same issue:
---
void main() {
    foreach(ref val; [3]) {
        auto del = { int j = val; };
        assert(&val != null); // Assertion failure
        assert(val == 3);
    }
}
---
and
---
void f(lazy int) { }

void main() {
    int i = 0;
    auto del = { int j = i; };

    foreach(ref val; [3]) {
        f(val);
        assert(&val != null); // Assertion failure
        assert(val == 3);
    }
}
---

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Apr 22 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6141


Kenji Hara <k.hara.pg gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull


--- Comment #3 from Kenji Hara <k.hara.pg gmail.com> 2012-11-09 02:18:16 PST ---
https://github.com/D-Programming-Language/dmd/pull/1272

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 09 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6141



--- Comment #4 from github-bugzilla puremagic.com 2012-11-09 04:16:03 PST ---
Commits pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/26870291ebcb9512bc3c7a3099719b3ef8596bd7
fix Issue 6141 - Bad code with ref-foreach and closures

https://github.com/D-Programming-Language/dmd/commit/8fc3e4b59bf5786accee257d301ca8de8cf8a277
Merge pull request #1272 from 9rnsr/fix8526

Issue 8526 & 6141 - DMD 2.060 regression: anonymous delegate call in foreach
loop

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 09 2012
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6141


Kenji Hara <k.hara.pg gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 09 2012