Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accessing enum' or static' member allocates gc closure #19312

Open
dlangBugzillaToGithub opened this issue Sep 4, 2017 · 1 comment
Open

Comments

@dlangBugzillaToGithub
Copy link

timon.gehr reported this on 2017-09-04T10:01:46Z

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

CC List

Description

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.
@dlangBugzillaToGithub
Copy link
Author

asumface commented on 2019-03-16T21:34:03Z

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant