Bug 14321 – Unnecessary destructor call with and AA's
Status
RESOLVED
Resolution
FIXED
Severity
major
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2015-03-23T11:03:00Z
Last change time
2015-06-17T21:02:49Z
Keywords
pull, wrong-code
Assigned to
nobody
Creator
rswhite4
Comments
Comment #0 by rswhite4 — 2015-03-23T11:03:04Z
Code:
----
import std.stdio;
struct Foo {
this(int id) {
writeln("CTor");
}
this(this) {
writeln("Postblit");
}
~this() {
writeln("DTor");
}
}
void main() {
Foo[string] foos;
foos["test"] = Foo(42);
writeln("end of main");
}
----
Expected behaviour
----
CTor
end of main
----
or
----
CTor
Postblit
DTor
end of main
----
But currently:
----
CTor
DTor
end of main
----
That ruins all interaction between AA's and ref counted structs.
Comment #1 by rswhite4 — 2015-03-23T11:05:08Z
Forget to mention, my compiler is DMD v2.067.0-rc1
Comment #2 by rswhite4 — 2015-03-23T11:07:33Z
(In reply to rswhite4 from comment #1)
> Forget to mention, my compiler is DMD v2.067.0-rc1
Seems to produce an ICE in 2.065:
http://dpaste.dzfl.pl/362689545fb6
Comment #3 by k.hara.pg — 2015-03-24T12:13:31Z
When an AA entry is newly created and initialized by the rvalue rhs, the value will be moved in the allocated slot. So the expected behavior is:
> ----
> CTor
> end of main
> ----
https://github.com/D-Programming-Language/dmd/pull/4512
Comment #4 by github-bugzilla — 2015-03-25T08:51:45Z