digitalmars.D - Why does destructor of global var isn't called?
- Dru (17/17) Dec 25 2018 example:
- Basilez B. (6/23) Dec 25 2018 `a`, since declared in the global scope, is constructed at
- Steven Schveighoffer (13/42) Dec 26 2018 That's the destructor of the temporary, not the `a`. Add a writeln("end
- Dru (5/5) Dec 26 2018 yeah it was reported
- Andrei Alexandrescu (2/8) Dec 26 2018 Reassigned to Razvan.
example: ----------- struct A{ int* arr; ~this() { writeln("A destruct"); } } static ~this() { writeln("module destruct"); } A a; void main() { } ----------- only prints "module destruct"
Dec 25 2018
On Tuesday, 25 December 2018 at 19:32:47 UTC, Dru wrote:example: ----------- struct A{ int* arr; ~this() { writeln("A destruct"); } } static ~this() { writeln("module destruct"); } A a; void main() { } ----------- only prints "module destruct"`a`, since declared in the global scope, is constructed at compile-time so its data are in executable dedicated segments (althoufh here it's just equal to A.init) and don't have to be destructed. Add `a = A(null); ` in main and the destructor gets called.
Dec 25 2018
On 12/25/18 3:46 PM, Basilez B. wrote:On Tuesday, 25 December 2018 at 19:32:47 UTC, Dru wrote:That's the destructor of the temporary, not the `a`. Add a writeln("end of main") at the end of main and you will see the destructor is called before main exits (while `a` is still alive). My expectation is that thread-local-storage variables are not destroyed. It's definitely an oversight, as things like refcounting would be screwed up if a reference is stored there. However, I think this will take some help from the compiler, and possibly we would have to put those destructors in a constructed static destructor, since there is no "type" that holds those variables. This seems like something for which a bug likely already exists, but feel free to file one if you don't find it. -Steveexample: ----------- struct A{ int* arr; ~this() { writeln("A destruct"); } } static ~this() { writeln("module destruct"); } A a; void main() { } ----------- only prints "module destruct"`a`, since declared in the global scope, is constructed at compile-time so its data are in executable dedicated segments (althoufh here it's just equal to A.init) and don't have to be destructed. Add `a = A(null); ` in main and the destructor gets called.
Dec 26 2018
yeah it was reported https://issues.dlang.org/show_bug.cgi?id=14650 Status: ASSIGNED Importance: P1 normal Assignee: Seb
Dec 26 2018
On 12/26/18 1:45 PM, Dru wrote:yeah it was reported https://issues.dlang.org/show_bug.cgi?id=14650 Status: ASSIGNED Importance: P1 normal Assignee: SebReassigned to Razvan.
Dec 26 2018