From 6ef89554a4413295b52f7c5bfa7e11e77d2b6594 Mon Sep 17 00:00:00 2001 From: Nick Treleaven Date: Sat, 27 Jul 2024 12:44:48 +0100 Subject: [PATCH] Fix Bugzilla 15315 - can break immutable with std.algorithm.move --- std/algorithm/mutation.d | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/std/algorithm/mutation.d b/std/algorithm/mutation.d index fbef28e5d56..c59234a47fa 100644 --- a/std/algorithm/mutation.d +++ b/std/algorithm/mutation.d @@ -1184,6 +1184,16 @@ pure nothrow @safe @nogc unittest assert(s53 is s51); } +unittest +{ + static struct S + { + immutable int i; + ~this() @safe {} + } + static assert(!__traits(compiles, { S a, b; move(a, b); })); +} + /// Ditto T move(T)(return scope ref T source) { @@ -1414,6 +1424,7 @@ private T trustedMoveImpl(T)(ref return scope T source) @trusted } private void moveEmplaceImpl(T)(ref scope T target, ref return scope T source) +if (__traits(compiles, target = T.init)) { import core.stdc.string : memcpy, memset; import std.traits : hasAliasing, hasElaborateAssign,