Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Destructors are not called on global variables #18998

Open
dlangBugzillaToGithub opened this issue Jun 4, 2015 · 6 comments
Open

Destructors are not called on global variables #18998

dlangBugzillaToGithub opened this issue Jun 4, 2015 · 6 comments

Comments

@dlangBugzillaToGithub
Copy link

Denis Shelomovskii (@denis-sh) reported this on 2015-06-04T12:08:05Z

Transferred from https://issues.dlang.org/show_bug.cgi?id=14650

CC List

Description

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.
@dlangBugzillaToGithub
Copy link
Author

verylonglogin.reg commented on 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.

@dlangBugzillaToGithub
Copy link
Author

andrei (@andralex) commented on 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!

@dlangBugzillaToGithub
Copy link
Author

dfj1esp02 commented on 2017-12-08T10:48:32Z

Well, it will have the same problems as static constructors.

@dlangBugzillaToGithub
Copy link
Author

issues.dlang (@jmdavis) commented on 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.

@dlangBugzillaToGithub
Copy link
Author

schveiguy (@schveiguy) commented on 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.

@dlangBugzillaToGithub
Copy link
Author

razvan.nitu1305 commented on 2018-12-27T13:01:11Z

PR: https://github.com/dlang/dmd/pull/9151

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant