Throwing exception in ~this causes SEGV in runtime.

Anonymous avatarAnonymous created an issue
class C
{
public:
    this()
    {
    }

    ~this()
    {
        writeln(this); // crash
    }
}

int main()
{
    C c = new C;
}

This does not crash the executable with DMD. Putting an assert in the destructor also it crash, not sure if that's a bug though: http://d.puremagic.com/issues/post_bug.cgi

Comments (4)

  1. Iain Buclaw

    There's nothing wrong with accessing members. Just when exceptions are thrown in the destruction stage of runtime.

    class C
    {
        ~this()
        {
            assert(0);
        }
    }
    
    void main()
    {
        C c = new C;
    }
    

    Changed OP to reflect a better minimal test case.

  2. Anonymous

    Well, the following also crashes on my system:

    import std.stdio;
    
    class C
    {
    public:
        ~this()
        {
            writeln(this);
        }
    }
    
    void main()
    {
        C c = new C;
    }
    

    Using: gdc -v2 main.d -o main.exe -static-libgcc -O2 -s -g -Wall On Win7 32bit.

  3. Log in to comment
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.