Bug 13099 – @nogc std.range.stride

Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2014-07-11T17:32:10Z
Last change time
2020-03-21T03:56:42Z
Assigned to
No Owner
Creator
bearophile_hugs

Comments

Comment #0 by bearophile_hugs — 2014-07-11T17:32:10Z
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 .