[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 16:52:55 UTC 2018
https://issues.dlang.org/show_bug.cgi?id=2043
--- Comment #29 from timon.gehr at gmx.ch ---
(In reply to Walter Bright from comment #27)
> D closures are "by reference" rather than "by value". I make use of it being
> by reference all the time, as well as it being much more efficient. Changing
> it would likely break all sorts of code. So then the question is, what to do
> if you want it by value?
> ...
No, this is not about this distinction. Other programming languages, even those
that always capture by reference, do not have this problem. This form of memory
corruption cannot reasonably be defined away as a language feature.
> Now, the compiler could actually rewrite the delegate into the nested form
> above, but as I said, this changes the semantics of existing code, as well as
> being pretty inefficient. I doubt it would be acceptable.
All bug fixes change behavior of existing code. The current behavior is
unacceptable.
--
More information about the Digitalmars-d-bugs
mailing list