Bug 17804 – Accessing `enum' or `static' member allocates gc closure

Status
NEW
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2017-09-04T10:01:46Z
Last change time
2024-12-13T18:54:24Z
Keywords
rejects-valid
Assigned to
No Owner
Creator
timon.gehr
Moved to GitHub: dmd#19312 →

Comments

Comment #0 by timon.gehr — 2017-09-04T10:01:46Z
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 by asumface — 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.
Comment #2 by robert.schadek — 2024-12-13T18:54:24Z
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