Bug 13935 – Problem with std.algorithm.cartesianProduct(map, map)

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2015-01-05T04:49:00Z
Last change time
2015-02-18T03:41:13Z
Keywords
pull, rejects-valid
Assigned to
nobody
Creator
bearophile_hugs

Comments

Comment #0 by bearophile_hugs — 2015-01-05T04:49:07Z
void main() { import std.algorithm: map, cartesianProduct; auto seq = [1, 2].map!(x => x); foreach (pair; cartesianProduct(seq, seq)) {} } dmd 2.067alpha gives: ...\dmd2\src\phobos\std\algorithm.d(14489,20): Error: function std.algorithm.cartesianProduct!(MapResult!(__lambda1, Result), MapResult!(__lambda1, Result)).cartesianProduct.Result.save cannot get frame pointer to main ...\dmd2\src\phobos\std\algorithm.d(14489,20): Error: function std.algorithm.cartesianProduct!(MapResult!(__lambda1, Result), MapResult!(__lambda1, Result)).cartesianProduct.Result.save cannot get frame pointer to main ...\dmd2\src\phobos\std\algorithm.d(14489,20): Error: function std.algorithm.cartesianProduct!(MapResult!(__lambda1, Result), MapResult!(__lambda1, Result)).cartesianProduct.Result.save cannot get frame pointer to main ...\dmd2\src\phobos\std\algorithm.d(14489,20): Error: function std.algorithm.cartesianProduct!(MapResult!(__lambda1, Result), MapResult!(__lambda1, Result)).cartesianProduct.Result.save cannot get frame pointer to main Taking a look at the std.algorithm.cartesianProduct implementation: auto cartesianProduct(RR...)(RR ranges) if (ranges.length >= 2 && allSatisfy!(isForwardRange, RR) && !anySatisfy!(isInfinite, RR)) { ... static struct Result { ... @property Result save() { Result copy; // Error message here ******* foreach (i, r; ranges) { copy.ranges[i] = r.save; copy.current[i] = current[i].save; } copy.empty = this.empty; return copy; } } ... -----------------------
Comment #1 by hsteoh — 2015-01-09T01:44:37Z
Comment #2 by github-bugzilla — 2015-01-10T07:44:27Z
Commits pushed to master at https://github.com/D-Programming-Language/phobos https://github.com/D-Programming-Language/phobos/commit/51e390d0bbc764e2866b1fb4c1c3fc532f6f7537 Issue 13935: do not assume range can be default-initialized. When the incoming range is parametrized on something that requires a frame pointer, we cannot declare default-initialized instances of its type; to work around this in .save, just make a copy of `this` and then kick it into shape before returning it. https://github.com/D-Programming-Language/phobos/commit/9a655323a16585ba9dc9b3ae547d51123a4f4b9d Merge pull request #2860 from quickfur/issue13935 Issue 13935: do not assume range can be default-initialized.
Comment #3 by github-bugzilla — 2015-02-18T03:41:13Z