[Issue 24046] New: static destructors should be allowed in function bodies
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Thu Jul 13 17:00:33 UTC 2023
https://issues.dlang.org/show_bug.cgi?id=24046
Issue ID: 24046
Summary: static destructors should be allowed in function
bodies
Product: D
Version: D2
Hardware: All
OS: All
Status: NEW
Severity: enhancement
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: b2.temp at gmx.com
Here is why : as we can hide static variables in function bodies there should
be a way to cleanup them.
A way to do that would be to allow local static destructors, for example
```d
struct S { }
S getS()
{
static S result;
static ~this() // run when the program finishes
{
destroy(result);
}
return result ? result : (result = new S);
}
```
--
More information about the Digitalmars-d-bugs
mailing list