mirror of
https://github.com/dlang/phobos.git
synced 2025-04-28 22:21:09 +03:00
Fix Bugzilla 15315 - can break immutable with std.algorithm.move (#9032)
This commit is contained in:
parent
7a14c896dd
commit
9ffe71fea3
2 changed files with 36 additions and 10 deletions
|
@ -1071,10 +1071,20 @@ Params:
|
|||
copy is performed.
|
||||
*/
|
||||
void move(T)(ref T source, ref T target)
|
||||
if (__traits(compiles, target = T.init))
|
||||
{
|
||||
moveImpl(target, source);
|
||||
}
|
||||
|
||||
/// ditto
|
||||
template move(T)
|
||||
if (!__traits(compiles, imported!"std.traits".lvalueOf!T = T.init))
|
||||
{
|
||||
///
|
||||
deprecated("Can't move into `target` as `" ~ T.stringof ~ "` can't be assigned")
|
||||
void move(ref T source, ref T target) => moveImpl(target, source);
|
||||
}
|
||||
|
||||
/// For non-struct types, `move` just performs `target = source`:
|
||||
@safe unittest
|
||||
{
|
||||
|
@ -1184,6 +1194,19 @@ pure nothrow @safe @nogc unittest
|
|||
assert(s53 is s51);
|
||||
}
|
||||
|
||||
@system unittest
|
||||
{
|
||||
static struct S
|
||||
{
|
||||
immutable int i;
|
||||
~this() @safe {}
|
||||
}
|
||||
alias ol = __traits(getOverloads, std.algorithm.mutation, "move", true)[1];
|
||||
static assert(__traits(isDeprecated, ol!S));
|
||||
// uncomment after deprecation
|
||||
//static assert(!__traits(compiles, { S a, b; move(a, b); }));
|
||||
}
|
||||
|
||||
/// Ditto
|
||||
T move(T)(return scope ref T source)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue