Bug 20869 – `std.algorithm.mutation : move` is overly trusting of `opPostMove`
Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
x86
OS
Mac OS X
Creation time
2020-05-28T10:30:30Z
Last change time
2020-09-15T06:21:54Z
Keywords
pull, safe
Assigned to
No Owner
Creator
Mathias LANG
Comments
Comment #0 by pro.mathias.lang — 2020-05-28T10:30:30Z
```
import std.algorithm.mutation;
struct S
{
void opPostMove(const ref S old) @system nothrow pure
{
int* ptr = cast(int*)42;
*ptr = 42;
}
int a;
}
void main () @safe nothrow
{
S s1;
s1.a = 41;
S s2 = move(s1);
assert(s2.a == 42);
}
```
Comment #1 by dlang-bot — 2020-05-28T15:51:20Z
@MoonlightSentinel created dlang/phobos pull request #7502 "Fix Issue 20869 - `move` is overly trusting of `opPostMove`" fixing this issue:
- Fix Issue 20869 - `move` is overly trusting of `opPostMove`
Remove the manual check whether move is `@safe` and instead let the
compiler do the attribute interference by adding appropriate @trusted
blocks.
Note:
I could've extend the current checks `trustedMoveImpl` but that could
easily miss other corner cases.
https://github.com/dlang/phobos/pull/7502
Comment #2 by dlang-bot — 2020-05-31T02:33:31Z
dlang/phobos pull request #7502 "Fix Issue 20869 - `move` is overly trusting of `opPostMove`" was merged into master:
- 082f8300d9d1a423b73cd31320bc86efa78a37e0 by MoonlightSentinel:
Fix Issue 20869 - `move` is overly trusting of `opPostMove`
Remove the manual check whether move is `@safe` and instead let the
compiler do the attribute interference by adding appropriate @trusted
blocks.
Note:
I could've extend the current checks `trustedMoveImpl` but that could
easily miss other corner cases.
https://github.com/dlang/phobos/pull/7502
Comment #3 by dlang-bot — 2020-09-15T06:21:54Z
dlang/druntime pull request #3133 "Backport move(Emplace) fixes from Phobos" was merged into master:
- aa829e3139fe93030bf68a8d216c6956188b4861 by MoonlightSentinel:
Fix Issue 20869 - `move` is overly trusting of `opPostMove`
Backport of dlang/phobos#7502
https://github.com/dlang/druntime/pull/3133