On 12/21/11 20:13, Kagamin wrote: >> Turned out not to be a good idea, as the compiler silently accepts >> "shared private static this() {...}" and does not emit the dead code anymore. >> But.. this constructor is run together with the un-shared ones, ie possibly >> _after_ them... (this is not section-gc specific, happens w/o it too) > > try `private shared static this()` > AFAIK static ctors have some attribute ordering issue.
Was going to follow up with exactly this. "private shared static this() { p("shared ctor2"); }" is a shared constructor "shared private static this() { p("shared ctor2"); }" is not, but the compiler won't even warn you about this. (in this case gdc, but i assume it's not gdc specific) >> import std.stdio; >> >> /* gcfuncdata2.d is a copy of this module, w/o main() */ >> import gcfuncdata2; >> >> auto p(S...)(S args) { return stdout.writeln(__FILE__~": ", args); } >> >> void main(string[] args){ p("main"); } >> >> static this() { p("ctor1"); } >> static this() { p("ctor2"); } >> shared static this() { p("shared ctor1"); } >> shared static this() { p("shared ctor2"); } >> >> static ~this() { p("dtor1"); } >> static ~this() { p("dtor2"); } >> shared static ~this() { p("shared dtor1"); } >> shared static ~this() { p("shared dtor2"); } >> >> unittest { p("unittest1"); } >> unittest { p("unittest2"); } > > Also add class static ctors and function static variables. But what would be the point? They should be GCed if unused and emitted, and wont be if something references them. artur