November 11, 2014 [Issue 13712] New: Templates don't resolve their static dtor order depending on passed in type | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=13712 Issue ID: 13712 Summary: Templates don't resolve their static dtor order depending on passed in type Product: D Version: D2 Hardware: All OS: All Status: NEW Severity: major Priority: P1 Component: DMD Assignee: nobody@puremagic.com Reporter: Marco.Leise@gmx.de 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. -- |
Copyright © 1999-2021 by the D Language Foundation