Bug 13654 – @nogc std.range.enumerate

Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2014-10-25T15:46:06Z
Last change time
2020-03-21T03:56:40Z
Keywords
rejects-valid
Assigned to
No Owner
Creator
bearophile_hugs

Comments

Comment #0 by bearophile_hugs — 2014-10-25T15:46:06Z
void main() @nogc { import std.algorithm: enumerate; int[1] arr; auto r = arr[].enumerate; } DMD 2.067alpha gives: test.d(4,19): Error: @nogc function 'D main' cannot call non-@nogc function 'std.range.enumerate!(uint, int[]).enumerate'
Comment #1 by bearophile_hugs — 2015-01-10T17:17:53Z
A possible solution is to replace this: auto enumerate(Enumerator = size_t, Range)(Range range, Enumerator start = 0) if (isIntegral!Enumerator && isInputRange!Range) ... if (overflow || result > Enumerator.max) throw new RangeError("overflow in `start + range.length`"); } } ... With this: auto enumerate(Enumerator = size_t, Range)(Range range, Enumerator start = 0) @nogc if (isIntegral!Enumerator && isInputRange!Range) ... if (overflow || result > Enumerator.max) { static immutable err = new RangeError("overflow in `start + range.length`"); throw err; } } } ... But I don't know if immutable errors are really correct.