[Issue 17661] New isInputRange rejects valid input range

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Thu Aug 3 11:49:42 PDT 2017


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

Martin Nowak <code at dawg.eu> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |code at dawg.eu

--- Comment #5 from Martin Nowak <code at 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.

--


More information about the Digitalmars-d-bugs mailing list