D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 13654 - @nogc std.range.enumerate
Summary: @nogc std.range.enumerate
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: x86 Windows
: P1 enhancement
Assignee: No Owner
URL:
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2014-10-25 15:46 UTC by bearophile_hugs
Modified: 2020-03-21 03:56 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description bearophile_hugs 2014-10-25 15:46:06 UTC
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 bearophile_hugs 2015-01-10 17:17:53 UTC
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.