Bug 15315 – can break immutable with std.algorithm.move
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P3
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2015-11-10T21:38:56Z
Last change time
2024-07-28T22:50:00Z
Keywords
pull, safe
Assigned to
No Owner
Creator
ag0aep6g
Comments
Comment #0 by ag0aep6g — 2015-11-10T21:38:56Z
Shown by Mike Parker in D.learn:
http://forum.dlang.org/post/[email protected]
----
static struct ku
{
immutable int id;
~this() @safe {}
}
void main() @safe
{
ku k1 = ku(1);
scope(exit) assert(k1.id == 1); /* fails */
ku k2 = ku(2);
scope(exit) assert(k2.id == 2); /* fails too, because there's a destructor */
import std.algorithm: move;
move(k2, k1);
}
----
Comment #1 by andrei — 2017-04-24T22:48:38Z
This should pass regardless of safe. The move function should simply copy the integer without overwriting it. This is because int does not have an elaborate postblit so it is cheap to copy.
Comment #2 by hsteoh — 2017-04-24T23:24:39Z
Wait, what? Aren't *both* k1.id and k2.id *immutable*? How could move(k2,k1) be valid, since it would overwrite k1, which violates the immutability of k1.id?
Comment #3 by andrei — 2017-04-25T01:23:22Z
Indeed, apologies. The target cannot be immutable.
Comment #4 by dlang-bot — 2024-07-27T11:49:18Z
@ntrel created dlang/phobos pull request #9032 "Fix Bugzilla 15315 - can break immutable with std.algorithm.move" fixing this issue:
- Fix Bugzilla 15315 - can break immutable with std.algorithm.move
https://github.com/dlang/phobos/pull/9032
Comment #5 by dlang-bot — 2024-07-28T22:50:00Z
dlang/phobos pull request #9032 "Fix Bugzilla 15315 - can break immutable with std.algorithm.move" was merged into master:
- dad7820d2aea4937f1ea1edc3340b9a7d454352a by Nick Treleaven:
Fix Bugzilla 15315 - can break immutable with std.algorithm.move
https://github.com/dlang/phobos/pull/9032