www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 20596] New: [REG2.086] Error on missed stack allocation for

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

          Issue ID: 20596
           Summary: [REG2.086] Error on missed stack allocation for
                    closure for template
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: regression
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: johanengelen weka.io

The following code used to compile but does not compile with DMD >= 2.086.1

File closuregc.d:
```
struct S
{
    void delegate()  nogc dg;

     nogc this(scope void delegate()  nogc dg)
    {
        this.dg = dg;
    }
}

 nogc void foo()
{
    int num;
    scope s = S(()  nogc { auto dummy = num; }); // No error.
}

struct STemplate(T)
{
    void delegate()  nogc dg;

     nogc this(scope void delegate()  nogc dg)
    {
        this.dg = dg;
    }
}

 nogc void fooTemplate()
{
    int num;
    scope s = STemplate!int(()  nogc { auto dummy = num; });
// closuregc.d(27): Error: function closuregc.fooTemplate is  nogc yet
allocates closures with the GC
// closuregc.d(30):        closuregc.fooTemplate.__lambda1 closes over variable
num at closuregc.d(29)
}
```

Compilation with -dip1000 does work, but without it it no longer works.

Note that the error only happens for the templated case. For the non-templated
struct, there is no problem.

--
Feb 22