www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 14807] New: unnecessary closure allocation for function

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

          Issue ID: 14807
           Summary: unnecessary closure allocation for function literal in
                    compile time test
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: code dawg.eu

cat > bug.d << CODE
void foo(int a)  nogc
{
    static if (__traits(compiles, { a = 2; }))
    {}
}
CODE

bug.d(1): Error: function bug.foo  nogc function allocates a closure with the
GC

----

Not sure if it's easy to detect the context of a function literal and see that
it can never be called.

--
Jul 17 2015