www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 19573] New: usage of delegate literals at compile-time

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

          Issue ID: 19573
           Summary: usage of delegate literals at compile-time allocates
                    closure at run-time
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: regnellday protonmail.com

Minimal example:
---
void main()
{
    int i;
    static assert(isCallable!(() => i)); // allocates
    static assert(is(typeof(() => i))); // ok
}

template isCallable(T...)
{
    enum bool isCallable = true;
}
---
dmd -vcg-ast output:
---
import object;
void main()
{
        int i = 0;
        return 0;
}
enum bool isCallable(T...) = true;
isCallable!(delegate () => i)
{
        enum bool isCallable = true;

}
---

--
Jan 10