Static constructors guaranteed to run?

via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Jun 29 03:19:33 PDT 2015


On Monday, 29 June 2015 at 02:07:57 UTC, ketmar wrote:
> On Sat, 27 Jun 2015 22:49:13 +0000, Tofu Ninja wrote:
>
>> On Saturday, 27 June 2015 at 22:20:40 UTC, ketmar wrote:
>>> 2. no.
>> 
>> Hmm...  any reason why?
>
> if instantiated template was not used in any code that makes 
> into compiled binary, compiler is free to remove it with all 
> it's ctors. it may do that, or may not, but removal is allowed. 
> so while that can work now (i didn't checked), it may stop 
> working in next version (or with another compiler), and that 
> will not be a bug.

Does the specification really say that? This isn't obvious to me 
at all. I would expect static ctors to be treated as if they were 
"referenced" by the initialization logic (though I understand 
it's not an explicit reference, they just end up in a special 
section that the runtime can inspect).


More information about the Digitalmars-d-learn mailing list