Bug 14650 – Destructors are not called on global variables

Status
ASSIGNED
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2015-06-04T12:08:05Z
Last change time
2024-12-13T18:43:09Z
Keywords
wrong-code
Assigned to
RazvanN
Creator
Denis Shelomovskii
Moved to GitHub: dmd#18998 →

Comments

Comment #0 by verylonglogin.reg — 2015-06-04T12:08:05Z
This program works fine but shouldn't: --- struct S { ~this() { assert(0); } } S s; void main() { } --- Destructors on global variables should be either prohibited or correctly called. Note: This issue was introduced by fixing Issue 6364. See Issue 6364, comment 2.
Comment #1 by verylonglogin.reg — 2015-06-04T12:14:26Z
In case this is an expected behavior (as written in issue 6437, comment 3), please provide reasons and link to documentation.
Comment #2 by andrei — 2017-12-07T16:49:13Z
Destructors are not called on function static objects, either. Seb, can you please check whether the language reference specifies that? Thanks!
Comment #3 by dfj1esp02 — 2017-12-08T10:48:32Z
Well, it will have the same problems as static constructors.
Comment #4 by issues.dlang — 2018-01-06T01:19:24Z
Yeah, I just tested this after a discussion static variables and their liftemos on D.Learn ------------------- import std.stdio; struct S { this(string foo) { _foo = foo; } ~this() { writefln("%s destroyed", _foo); } string _foo; } void main() { static mainStatic = S("main"); auto s = S("local"); f(); } void f() { static fStatic = S("f"); } ------------------- It just prints out local destroyed The variables for the static destructors are never called.
Comment #5 by schveiguy — 2018-01-06T01:27:58Z
Not calling destructors of thread-local variables at the end of the program could potentially be considered expected behavior. But not calling them at the end of thread termination is a big problem. As D gets closer to reference counting, sane destruction calls are going to become more and more important.
Comment #6 by razvan.nitu1305 — 2018-12-27T13:01:11Z
Comment #7 by robert.schadek — 2024-12-13T18:43:09Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/18998 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB