D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 17804 - Accessing `enum' or `static' member allocates gc closure
Summary: Accessing `enum' or `static' member allocates gc closure
Status: NEW
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P3 normal
Assignee: No Owner
URL:
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2017-09-04 10:01 UTC by timon.gehr
Modified: 2024-12-13 18:54 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description timon.gehr 2017-09-04 10:01:46 UTC
struct S{
    enum n=1;
}
struct T{
    static n=1;
}

void foo(S v)@nogc{
    auto f=()=>v.n; // error
}
void bar(T v)@nogc{
    auto f=()=>v.n; // error
}

This code should compile.

Also see issue 17800.
Comment 1 asumface 2019-03-16 21:34:03 UTC
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.
Comment 2 dlangBugzillaToGithub 2024-12-13 18:54:24 UTC
THIS ISSUE HAS BEEN MOVED TO GITHUB

https://github.com/dlang/dmd/issues/19312

DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB