[Issue 14306] New: Wrong codegen with -inline for generic lambdas

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Wed Mar 18 09:55:19 PDT 2015


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

          Issue ID: 14306
           Summary: Wrong codegen with -inline for generic lambdas
           Product: D
           Version: D2
          Hardware: x86
                OS: Linux
            Status: NEW
          Severity: critical
          Priority: P1
         Component: DMD
          Assignee: nobody at puremagic.com
          Reporter: andrei at erdani.com

Consider:

import std.algorithm, std.range;

struct S {
    int x;
    int bump() { ++x; return x; }
}

int[] fun(ref S s) {
    auto a = iota(100).map!(x => s.bump).array;
    return a;
}

void main() {
    S s;
    auto a = fun(s);
    assert(s.x == 100);
}

If built without -inline, the code works. Adding -inline makes the assertion
fail (s.x is 0).

Changing the lambda from x => s.bump to (int x) => s.bump makes the code work,
so this is an issue with inlining generic lambdas.

--


More information about the Digitalmars-d-bugs mailing list