[Issue 17804] Accessing `enum' or `static' member allocates gc closure

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sat Mar 16 21:34:03 UTC 2019


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

asumface at gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |asumface at gmail.com

--- Comment #1 from asumface at gmail.com ---
To add to this, consider the following code:

import std.algorithm;
struct Foo
{
    static int fun(int n)
    {
        return n + 1;
    }
}

void main()
{
    int[10] arr;
    Foo foo;
    arr[].map!(n => foo.fun(n));
}

the line
    arr[].map!(n => foo.fun(n));
causes GC allocation, whereas the same line with foo replaced with its type
    arr[].map!(n => Foo.fun(n));
does not. This is despite the functionality being absolutely identical as fun
has no dependency on 'this' whatsoever due to being a static member.

--


More information about the Digitalmars-d-bugs mailing list