Bug 24806 – Allocate a struct by new on stack with scope

Status
NEW
Severity
enhancement
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2024-10-12T13:11:41Z
Last change time
2024-12-13T19:38:02Z
Assigned to
No Owner
Creator
Richard (Rikki) Andrew Cattermole
Moved to GitHub: dmd#20530 →

Comments

Comment #0 by alphaglosined — 2024-10-12T13:11:41Z
A nice optimization to have is to allocate memory on the stack when it is scope. This is applied for classes, but not structs. https://dlang.org/spec/attribute.html#scope-class-var ```d struct S { } scope s = new S; // heap allocated ```
Comment #1 by aldacron — 2024-10-13T08:13:30Z
What would be the point of that? Why would anyone want to do that instead of S s; ?
Comment #2 by robert.schadek — 2024-12-13T19:38:02Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/20530 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB