www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 15661] New: Destructor called while object still alive

https://issues.dlang.org/show_bug.cgi?id=15661

          Issue ID: 15661
           Summary: Destructor called while object still alive
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Windows
            Status: NEW
          Severity: major
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: matt.elkins gmail.com

In the code below the TileView destructor is called twice (see the output at
the bottom). The first call of the destructor appears to occur while the
TileView object is still alive. The expected output (also listed at the bottom)
occurs if any of a number of changes are made to the code, including but
probably not limited to:
* Creating the TextureHandles directly rather than calling create()
* Using only one argument to TileView's constructor
* Removing TextureHandle's empty destructor

This is on DMD 2.070 32-bit, running on 64-bit Windows 7.

[code]
import std.stdio;

struct TextureHandle
{
    ~this() {}
}

TextureHandle create() {return TextureHandle();}

 struct TileView
 {
      disable this();
      disable this(this);
     this(TextureHandle a, TextureHandle b) {}
     ~this() {writeln("HERE2");}
 }

 struct View
 {
     this(int)
     {
         writeln("HERE1a");
         m_tileView = TileView(create(), create());
         writeln("HERE1b");
     }

     private TileView m_tileView;
}

unittest
{
    auto v = View(5);
}
[/code]

[output]
HERE1a
HERE2
HERE1b
HERE2
[/output]

[expected_output]
HERE1a
HERE1b
HERE2
[/expected_output]

--
Feb 08 2016