[Issue 23204] New: [REG2.097] discarded scope return still allocates GC closure

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Jun 22 09:37:00 UTC 2022


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

          Issue ID: 23204
           Summary: [REG2.097] discarded scope return still allocates GC
                    closure
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: regression
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: johanengelen at weka.io

Testcase:
```
auto invoker(Dlg)(scope Dlg dlg) { return dlg; }  // <--- `return` is inferred
on parameter

// Does not compile, but should.
@nogc void f(int x) { invoker({x++;}); }  // <--- return value is discarded,
hence does not escape the scope.

// This compiles fine, without gc allocation:
@nogc void g(int x) {
    scope inv = invoker({x++;});
    inv();
}
```

Compilation succeeds with 2.096, fails with 2.097 with the error:
<source>(3): Error: function `example.f` is `@nogc` yet allocates closures with
the GC
<source>(3):        example.f.__lambda2 closes over variable x at <source>(3)
C

The regression is related to the fix for
https://issues.dlang.org/show_bug.cgi?id=21912

--


More information about the Digitalmars-d-bugs mailing list