Static constructors guaranteed to run?

ketmar via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Jun 29 04:36:42 PDT 2015


On Mon, 29 Jun 2015 10:19:33 +0000, Marc Schütz wrote:

> 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).

it doesn't, afair, but it's quite natural. if user type was throwed out 
as unused, it would be very strange to insist on keeping it's 
initialization code.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: not available
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20150629/30b6855d/attachment.sig>


More information about the Digitalmars-d-learn mailing list