www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 19828] New: maxElement give wrong results

https://issues.dlang.org/show_bug.cgi?id=19828

          Issue ID: 19828
           Summary: maxElement give wrong results
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: critical
          Priority: P1
         Component: phobos
          Assignee: nobody puremagic.com
          Reporter: jeromerichard111 msn.com

Hello,

The following code give the result 4 with recent compiler (DMD, LDC) versions
while the correct result is 1.
GDC and an old DMD give the correct result while LDC and the newer versions of
DMD fail.

The version tested is LDC 1.15.0 from the Nix package manager (last package
update).
The same issue appear in LDC 1.12.0 from the Debian testing repository.
The latest CI version seems to produce the same result:
https://godbolt.org/z/rdnwH3 .
According to run.dlang.io, it worked for DMD up to version 2.079 (returning 1),
but regressed since v2.080 (returning 4).

See the previous issue (3064) sent to LDC for more information.

Moreover, it seems affected by whether using a lambda or not.


module main;
import std.stdio;
import std.range;
import std.algorithm.searching;

void main(string[] args)
{
        int[] tab = [1, 2, 3, 4];
        int[] arr = [23, 42, 17, 5, 31];
        tab.maxElement!((i) { return arr[i]; }).writeln;
}

--
Apr 26 2019