www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 23204] New: [REG2.097] discarded scope return still allocates


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

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++;});

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)

The regression is related to the fix for

Jun 22 2022