[Issue 14653] scoped!range in foreach crashes

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Wed Jun 17 06:10:20 PDT 2015


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

--- Comment #4 from Ketmar Dark <ketmar at ketmar.no-ip.org> ---
a simplified sample:

===================
import std.stdio : writeln;

struct SomeRangeType {
  int a;
  alias front = a;
  void popFront () { ++a; }
  @property bool empty () { return (a >= 2); }
}

auto wrapit () {
  static struct Wrapper {
    SomeRangeType rng;
    alias rng this;
    @disable this (this);
    ~this () { writeln("wrapper dtor"); }
  }
  return Wrapper(SomeRangeType());
}

void main () {
  writeln("before foreach");
  foreach (auto e; wrapit()) {
    writeln("in foreach; e=", e);
  }
  writeln("after foreach");
}
===================

this prints:
---
before foreach
wrapper dtor
in foreach; e=0
in foreach; e=1
after foreach
--

what i expected it to print:
---
before foreach
in foreach; e=0
in foreach; e=1
wrapper dtor
after foreach
---

--


More information about the Digitalmars-d-bugs mailing list