[Issue 2043] Closure outer variables in nested blocks are not allocated/instantiated correctly: should have multiple instances but only have one.

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Apr 5 22:15:06 UTC 2018


https://issues.dlang.org/show_bug.cgi?id=2043

--- Comment #35 from Walter Bright <bugzilla at digitalmars.com> ---
1. alloca() won't work, because that won't survive the end of the function.

2. Doing a heap alloc/free for every loop iteration is expensive, and since the
cost is hidden it will come as a nasty surprise.

3. Doing a gc allocation will generate an unbounded set of allocations, also
coming as a nasty surprise.

4. Doing my delegate rewrite will cause a "by value" which changes the
semantics, so that won't work.

I suspect the pragmatic solution is to disallow the capture of loop variables
by reference by escaping delegates. The user then will be notified of the
problem, and he can construct an efficient workaround that works for his
application.

--


More information about the Digitalmars-d-bugs mailing list