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