Bug 12610 – std.algorithm.reduce (with seed) and array-wise operation produces incorrect result

Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2014-04-21T22:57:00Z
Last change time
2014-04-23T16:22:53Z
Assigned to
nobody
Creator
acehreli

Comments

Comment #0 by acehreli — 2014-04-21T22:57:51Z
The following program produces incorrect and random results like [373728176], [-2022052576], etc. (Build *without* -inline.) import std.stdio; import std.algorithm; void main() { int[] arr = [ 0 ]; int[1] seed; int[] result = reduce!((sum, _) => sum[])(seed, arr); writefln("%s", result); } Any of the following is sufficient to cover up the issue: * Building with -inline * Not slicing sum inside the lambda but returning it directly (i.e. => sum) * Inserting a writefln expression inside the lambda Ali
Comment #1 by acehreli — 2014-04-23T16:22:53Z
This turned out to be a user error after the following discussion: http://forum.dlang.org/thread/[email protected] (The user should not return a slice to the internal seed variable that reduce uses.) Ali