Bug 15661 – [REG2.067.0] Destructor called while object still alive

Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2016-02-09T00:19:00Z
Last change time
2016-02-23T10:04:31Z
Keywords
pull, wrong-code
Assigned to
nobody
Creator
matt.elkins

Comments

Comment #0 by matt.elkins — 2016-02-09T00:19:12Z
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]
Comment #1 by kozzi11 — 2016-02-09T07:47:20Z
in 2.066.1 and before it works as expected
Comment #2 by k.hara.pg — 2016-02-09T13:51:11Z
Also happens with Win32.
Comment #3 by k.hara.pg — 2016-02-09T14:05:26Z
Comment #4 by k.hara.pg — 2016-02-09T15:24:10Z
Comment #5 by github-bugzilla — 2016-02-16T13:35:53Z
Commits pushed to stable at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/5a235b87ddbbdd01e08106ce099f31c72b670043 fix Issue 15661 - Destructor called while object still alive By the PR #4078, some preparation code has been inserted before a constructor call expression. Then, `AssignExp` had failed to recognize the ctor call form. https://github.com/D-Programming-Language/dmd/commit/06a5ae5077e6e7ae9da01fb3293b3df6ce7c1a84 Merge pull request #5431 from 9rnsr/fix15661 [REG2.067.0] Issue 15661 - Destructor called while object still alive
Comment #6 by github-bugzilla — 2016-02-23T10:04:31Z