[Issue 24806] New: Allocate a struct by new on stack with scope

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sat Oct 12 13:11:41 UTC 2024


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

          Issue ID: 24806
           Summary: Allocate a struct by new on stack with scope
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: alphaglosined at gmail.com

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
```

--


More information about the Digitalmars-d-bugs mailing list