Bug 8055 – [Regression 2.059] std.algorithm.move corrupts moved object field
Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-05-06T19:16:00Z
Last change time
2012-05-08T11:05:56Z
Keywords
pull, wrong-code
Assigned to
nobody
Creator
k.hara.pg
Comments
Comment #0 by k.hara.pg — 2012-05-06T19:16:22Z
import std.algorithm;
struct S
{
int x;
~this()
{
assert(x == 0); // Line7
}
}
S foo(S s)
{
return move(s);
}
void main()
{
S a;
a.x = 0;
auto b = foo(a);
assert(b.x == 0);
}
Comment #1 by k.hara.pg — 2012-05-06T19:27:29Z
Sorry, I accidentally posted that is only half written.
(In reply to comment #0)
> import std.algorithm;
> struct S
> {
> int x;
> ~this()
> {
> assert(x == 0); // Line7
> }
> }
> S foo(S s)
> {
> return move(s);
> }
> void main()
> {
> S a;
> a.x = 0;
> auto b = foo(a);
> assert(b.x == 0);
> }
output:
----
core.exception.AssertError@test(7): Assertion failure
This regression is introduced this commit:
https://github.com/D-Programming-Language/phobos/commit/71b1c1a
In unary move(), result is uninitialized. If T has an elaborate destructor, it is called on corrupted memory.