In Windows platform, the code will raise a runtime error "Integer Divide by Zero" with 2.066 and git-head (2.067alpha). But the issue does not occur with 2.065.
Comment #3 by drug2004 — 2014-08-28T14:53:15Z
Yes, this is 2.066 regression.
Is it suitable decision instead of:
this(R input, size_t index = 0)
{
_original = input;
_index = index % _original.length;
}
use this
this(R input, size_t index = 0)
{
_original = input;
_index = (_original.length) ? index % _original.length : 0;
}
If yes I can make PR.
Comment #4 by hsteoh — 2014-08-28T22:44:10Z
Sounds reasonable, though I would write "(_original.length > 0) ? ..." for clarity's sake.
Comment #5 by drug2004 — 2014-08-29T06:54:42Z
I agree with clarity. But I'm not sure if cycle may be empty at all, that's the question, I guess...
Comment #6 by monarchdodra — 2014-08-29T10:24:46Z
(In reply to drug007 from comment #5)
> I agree with clarity. But I'm not sure if cycle may be empty at all, that's
> the question, I guess...
I believe cycle should not be passed an empty range. Or to be more precise, the underlying range may not at any point in time become empty.
The reasoning for this is that cycle is an infinite range, meaning it can be *statically* verified as being not empty.
Now, it is always incorrect for phobos to produce a crash. At the very least, an assert should be placed. Furthermore, I don't really believe that the constructor should fail. Rather, the operations pop should error out, and the operations front should index out of bounds.
And we should document the error. I'm on it.
Comment #7 by code — 2014-10-07T00:08:12Z
When was this bug introduced?
Any fix in sight?
Comment #8 by hsteoh — 2014-10-07T00:25:40Z
I'm surprised this worked in older releases. Or *appears* to work -- it's probably actually broken because cycle() returns an infinite range, but when the input is empty, it can't be an infinite range. So this is one of those places where the compile-time requirement of isInfinite breaks down.
Comment #9 by monarchdodra — 2014-10-07T07:40:37Z
(In reply to Martin Nowak from comment #7)
> When was this bug introduced?
I don't know if it's a bug, but I think I introduced it. I don't remember the details though.
> Any fix in sight?
I remember having started a fix, and I still have the branch. I thought it would be as simple as placing an assert, but it turned out asserting in the constructor is over-eager, yet asserting in front is wasteful.
I need to review what I had written...