Bug 13712 – Templates don't resolve their static dtor order depending on passed in type

Status
NEW
Severity
major
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2014-11-11T10:54:03Z
Last change time
2024-12-13T18:33:59Z
Assigned to
No Owner
Creator
Marco Leise
Moved to GitHub: dmd#18909 →

Comments

Comment #0 by Marco.Leise — 2014-11-11T10:54:03Z
Whenever we have static dtors in templates, we risk that the template arguments introduce a "hidden" dependency. Usually destructor call order is resolved by looking at imported modules. In case of templates, their surrounding module does not need to import any other modules to be able to use a type `T`. Now if `T` itself comes out of a module with static dtors, that otherwise has no connection with the template and module in question, the compiler will not take note of it and the runtime may call static dtors from both module in the wrong order. This usually leads to access violations on application shutdown. A typical example where this happens is when you have one module with a singleton template, where a shared dtor destroys it, and another module with some globally managed templated resource. Now if you create a singleton class containing such a resource, the singleton's module misses that it depends on the resource's module for construction/destruction. When instantiating a template the compiler must emit dependencies for the module containing the template on any types used in the template arguments, whether they are passed in directly or as part of an alias expression such as a function return type. Before that, we cannot safely use singletons and other global resources in D.
Comment #1 by schveiguy — 2014-11-11T13:13:39Z
Can you show a simple example of the bad behavior that you think should work?
Comment #2 by robert.schadek — 2024-12-13T18:33:59Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/18909 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB