DIP 1022---foreach auto ref---Community Review Round 2
nospam at example.com
Wed Oct 23 08:41:54 UTC 2019
On Wednesday, 23 October 2019 at 07:25:40 UTC, Dukc wrote:
> On Saturday, 19 October 2019 at 13:16:17 UTC, Mike Parker wrote:
>> This is the feedback thread for the second round of Community
>> Review for DIP 1022, "foreach auto ref":
> In case someone does not have concentration to see what's
> changed relative to the first community review, the major
> things are:
> -`static foreach` is no longer supposed to compile with `auto
> ref`. Rationale of why in description.
> -added a simplified example in bottom of rationale section
I'm the author of that pull request. Reading your DIP I think you
give a misinterpretation of it.
"A pull request was submitted to disallow this behavior.
In every place where foreach (ref <...>) presently iterates by
value, a compiler error would have resulted after merging that
My patch was not supposed to give any error. And I didn't even
try to disallow this behaviour.
Before that patch, compiler allowed to iterate a range of structs
(where front is returned by value) by ref, that probably doesn't
make any sense. In this case dtor on those structs is never
called due to a bug in code. This mean that if my struct wrap a
"malloc" call in struct's ctor and a "free" call in struct's dtor
(or a refcount like in my case) memory is saturated using a
foreach (or simply usign phobos "each!T").
My patch simply fixed that missing dtor call, and I left the
behaviour change for a complex DIP.
Sönke Ludwig summarized  this better than me in a comment on
"Isn't this quite simple? Fixing the failure to call the
destructor is critical and a clear improvement over the status
quo. The ref foreach didn't ever do something useful for r-value
ranges, but that's an orthogonal issue that should simply be
discussed in the context of a separate ticket (or DIP)."
More information about the Digitalmars-d