D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 8055 - [Regression 2.059] std.algorithm.move corrupts moved object field
Summary: [Regression 2.059] std.algorithm.move corrupts moved object field
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: All All
: P2 regression
Assignee: No Owner
URL:
Keywords: pull, wrong-code
Depends on:
Blocks:
 
Reported: 2012-05-06 19:16 UTC by Kenji Hara
Modified: 2012-05-08 11:05 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Kenji Hara 2012-05-06 19:16:22 UTC
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 Kenji Hara 2012-05-06 19:27:29 UTC
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.
Comment 3 github-bugzilla 2012-05-08 10:14:46 UTC
Commits pushed to master at https://github.com/D-Programming-Language/phobos

https://github.com/D-Programming-Language/phobos/commit/279963c9d0351809f1cab76f861af8a4832c1ec9
fix Issue 8055 - std.algorithm.move corrupts moved object field

https://github.com/D-Programming-Language/phobos/commit/892038953dfd645952a482a06f692ea6fba2f437
Merge pull request #572 from 9rnsr/fix_move

Issue 8055 & 8057 - Fix std.algorithm.move issues