Bug 24425 – @standalone attribute should be usable on thread-local static constructors and all static destructors

Status
NEW
Severity
enhancement
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2024-03-01T03:29:11Z
Last change time
2024-12-13T19:33:43Z
Assigned to
No Owner
Creator
Steven Schveighoffer
Moved to GitHub: dmd#18219 →

Comments

Comment #0 by schveiguy — 2024-03-01T03:29:11Z
This is a valid use of standalone constructors and should be allowed: ```d import core.attribute; int *foo; @standlone @system static this() { foo = new int(10); } ``` Yet, the compiler doesn't allow this usage. I'm unsure whether the compiler needs to do anything fancy here. There is an `MIstandalone` flag, which means all shared *and* thread-local static ctors of a module are standalone. And there is also an `ictor` function pointer which appears to be independent construction for a module. I'm not sure how each is used, but I would imagine constructing a "dummy" moduleinfo that contains only standalone ctors/dtors (by using the MIstandalone flag) is possible whenever needed. I know that druntime already would handle this case properly.
Comment #1 by schveiguy — 2024-03-01T03:36:43Z
Static destructors can also benefit from being marked standalone, though the use case isn't as compelling. However, there is no reason to disallow it. A standalone destructor would be run last when sorting ctors/dtors (this naturally already happens).
Comment #2 by robert.schadek — 2024-12-13T19:33:43Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/18219 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB