Bug 13091 – nothrow std.algorithm.cartesianProduct

Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2014-07-10T22:10:00Z
Last change time
2014-09-19T11:35:33Z
Keywords
pull
Assigned to
nobody
Creator
bearophile_hugs

Comments

Comment #0 by bearophile_hugs — 2014-07-10T22:10:01Z
void main() pure nothrow @safe @nogc { import std.algorithm: cartesianProduct; int[1] a = [1]; foreach (t; cartesianProduct(a[], a[])) {} } dmd 2.066beta2 gives me: test.d(4,33): Error: pure function 'D main' cannot call impure function 'std.algorithm.cartesianProduct!(int[], int[]).cartesianProduct' test.d(4,33): Error: @nogc function 'D main' cannot call non-@nogc function 'std.algorithm.cartesianProduct!(int[], int[]).cartesianProduct' test.d(4,5): Error: pure function 'D main' cannot call impure function 'std.algorithm.joiner!(MapResult!(__lambda3, int[])).joiner.Result.popFront' test.d(4,5): Error: @nogc function 'D main' cannot call non-@nogc function 'std.algorithm.joiner!(MapResult!(__lambda3, int[])).joiner.Result.popFront' test.d(4,33): Error: 'std.algorithm.cartesianProduct!(int[], int[]).cartesianProduct' is not nothrow test.d(4,5): Error: 'std.algorithm.joiner!(MapResult!(__lambda3, int[])).joiner.Result.popFront' is not nothrow test.d(1,6): Error: function 'D main' is nothrow yet may throw
Comment #1 by hsteoh — 2014-09-19T00:48:45Z
Comment #2 by github-bugzilla — 2014-09-19T08:40:52Z
Commits pushed to master at https://github.com/D-Programming-Language/phobos https://github.com/D-Programming-Language/phobos/commit/556ef61ef8ede92f06b05e233cf7521f5042a18c Use new cartesianProduct implementation for 2-argument case as well. The original implementation will now only be used when one or both the ranges is either non-forward or infinite. The new implementation is also more attribute-friendly (works with pure, nothrow, @nogc, @safe), so this also fixes issue 13091. https://github.com/D-Programming-Language/phobos/commit/2bd311c0edf3ecb4d8faa988a3ce2f468479d06f Merge pull request #2534 from quickfur/issue13091 Use new cartesianProduct implementation for 2-argument case as well.
Comment #3 by bearophile_hugs — 2014-09-19T11:35:33Z
Thank you. Do you know the cause of this problem? void main() @safe { import std.algorithm: cartesianProduct; import std.array: array; const r = cartesianProduct([1], [1]).array; } test.d(4,41): Error: safe function 'D main' cannot call system function 'std.array.array!(Result).array'