D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 13099 - @nogc std.range.stride
Summary: @nogc std.range.stride
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:
Depends on:
Blocks:
 
Reported: 2014-07-11 17:32 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-07-11 17:32:10 UTC
void main() @nogc {
    import std.range: stride;
    int[] a;
    a.stride(2);
}


dmd 2.066beta gives:

test.d(4,13): Error: @nogc function 'D main' cannot call non-@nogc function 'std.range.stride!(int[]).stride'


Currently std.range.stride is not @nogc just because of this enforce:


auto stride(Range)(Range r, size_t n) @nogc
if (isInputRange!(Unqual!Range))
{
    import std.exception : enforce;

    enforce(n > 0, "Stride cannot have step zero.");
...



The given code compiles if you replace the enforce with:


    immutable static exc = new Exception("Stride cannot have step zero.");
    if (n == 0)
        throw exc;



But look at the comment by monarchdodra in Issue 12768 .