Bug 8057 – std.algorithm.move cannot use for nested struct

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-05-06T20:31:00Z
Last change time
2012-11-03T14:13:50Z
Keywords
pull, wrong-code
Assigned to
nobody
Creator
k.hara.pg

Comments

Comment #0 by k.hara.pg — 2012-05-06T20:31:19Z
import std.algorithm; void main() { int n = 10; struct S { int x; ~this() { // Access to enclosing scope assert(n == 10); // Line11 } } S foo(S s) { // Move nested struct return move(s); } S a; a.x = 1; auto b = foo(a); import core.stdc.stdio; printf("a.x = %d\n", a.x); assert(b.x == 1); } output: ---- core.exception.AssertError@test(11): Assertion failure
Comment #1 by k.hara.pg — 2012-05-06T20:39:21Z
Comment #2 by github-bugzilla — 2012-05-08T10:14:42Z
Commits pushed to master at https://github.com/D-Programming-Language/phobos https://github.com/D-Programming-Language/phobos/commit/dc6fb32f8749138ec9304c8e5e1b009b5d5dcb2e fix Issue 8057 - std.algorithm.move cannot use for nested struct 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
Comment #3 by verylonglogin.reg — 2012-11-03T12:35:32Z
S's destructor is incorrect, as you always can set `S s = S.init` and the destructor must process that correctly. Corrected destructor variant: --- ~this() { + // Struct always can equal to its `init` <- added + if(this == S.init) return; <- added // Access to enclosing scope assert(n == 10); // Line11 } ---
Comment #4 by verylonglogin.reg — 2012-11-03T14:13:50Z
(In reply to comment #3) > S's destructor is incorrect, as you always can set `S s = S.init`... And also because of `destroy` existance. This behavior is fixed in https://github.com/D-Programming-Language/phobos/pull/923