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

Martin Nowak <c...@dawg.eu> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |c...@dawg.eu

--- Comment #5 from Martin Nowak <c...@dawg.eu> ---
Well in, (R r) return => r.front, the return applies to the delegate context,
but you're escaping a reference to the argument.
What you want to check is `(return ref R r) => r.front`.

Also rewriting your front methods to a free functions helps understanding.

  C front(return ref S _this) { return C(&_this); }

Obviously allowing

  (R r) => front(r)

would return a dangling reference to the value parameter.

NB, if your front methods leaked a field of the range (e.g. a pointer), you'd
need a `return scope` front methods, but the `(R r) => r.front` check is fine,
since the parameter `r` isn't scoped, i.e. it might leak any pointer fields.

--

Reply via email to