Static constructors guaranteed to run?

Tofu Ninja via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Jun 28 19:19:54 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.

Can you say the same about non templated static constructors? 
Like if a type is never used but it has a static constructor, is 
the compiler free to remove that as well?


More information about the Digitalmars-d-learn mailing list