Bug 9123 – std.algorithm.reduce is not pure nothrow on const array
Status
RESOLVED
Resolution
WORKSFORME
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2012-12-07T16:24:00Z
Last change time
2014-02-25T12:24:50Z
Keywords
rejects-valid
Assigned to
nobody
Creator
bearophile_hugs
Comments
Comment #0 by bearophile_hugs — 2012-12-07T16:24:22Z
In this program spam1 and spam2 differ because 'items' is const in spam2:
import std.algorithm: reduce;
struct Foo {}
immutable Foo zero;
static Foo bar(Foo, Foo) pure nothrow {
return zero;
}
void spam1(Foo[] items) pure nothrow {
reduce!bar(zero, items);
}
void spam2(const Foo[] items) pure nothrow {
reduce!bar(zero, items);
}
void main() {}
Expected: both spam1 and spam2 allowed to be pure nothrow.
But DMD 2.061alpha gives:
test.d(11): Error: pure function 'spam2' cannot call impure function 'reduce'
test.d(11): Error: reduce is not nothrow
test.d(10): Error: function test.spam2 'spam2' is nothrow yet may throw
Comment #1 by monarchdodra — 2014-02-25T12:24:50Z
Don't know when fixed, but the snippet works fine now in head.