Bug 11294 – Object destruction with alias this

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
druntime
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-10-18T17:03:05Z
Last change time
2018-11-29T00:06:18Z
Assigned to
Stanislav Blinov
Creator
SHOO

Comments

Comment #0 by zan77137 — 2013-10-18T17:03:05Z
This code makes the behavior of the program strange: ---------------- /+ extern(C) void rt_finalize(void *ptr, bool det=true); void clear(T)(T obj) if (is(T == class)) { rt_finalize(cast(void*)obj); } +/ import std.stdio; class A { ~this(){writeln("A");} int dummy; } class B { A a; int dummy; alias a this; ~this(){writeln("B");} } void main() { auto a = new A; auto b = new B; b.a = a; writeln(b.dummy); clear(b); writeln(a.dummy); writeln("END"); } RESULT: ---------------- $ dmd -run main 0 A 0 END B ---------------- It is a problem to access the member of the destructed object. So, the result should be like this: ---------------- $ dmd -run main 0 B 0 END A --------------- Because alias this is given priority to in the `cast(void*)obj`, this problem occurs.
Comment #1 by github-bugzilla — 2018-11-27T01:50:12Z
Commits pushed to master at https://github.com/dlang/druntime https://github.com/dlang/druntime/commit/3b9c093d9957ebe90ee812f1d07c5d876094d034 Fix Issue 11294 - Object destruction with alias this https://github.com/dlang/druntime/commit/4fd4fa32e6acd82f1c9fcd2084e6d9066281a67e Merge pull request #2366 from radcapricorn/fix11294 Fix Issue 11294 - Object destruction with alias this merged-on-behalf-of: Nicholas Wilson <[email protected]>
Comment #2 by github-bugzilla — 2018-11-29T00:06:18Z
Commits pushed to master at https://github.com/dlang/dmd https://github.com/dlang/dmd/commit/6e65ca834e8bbde62d92f9e21530b6ac7a07c0f0 Fix Issue 13392 and 11294 - class + alias this + cast(void*) == overzealous cast https://github.com/dlang/dmd/commit/42c71012e75b80431e83367dcbb0a37a5fea91bb Merge pull request #9017 from RazvanN7/Issue_11294 Fix Issue 13392 and 11294 - class + alias this + cast(void*) == overzealous cast merged-on-behalf-of: Nicholas Wilson <[email protected]>