Skip to content
This repository was archived by the owner on Oct 12, 2022. It is now read-only.

Commit 9ba9a6a

Browse files
authored
Merge pull request #3799 from RazvanN7/Issue_22766
Fix Issue 22766 - copyEmplace does not work with copy constructor and @disable this() Signed-off-by: Dennis <dkorpel@users.noreply.github.com> Merged-on-behalf-of: Dennis <dkorpel@users.noreply.github.com>
2 parents 31ec2e8 + 5b81f1c commit 9ba9a6a

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

src/core/lifetime.d

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1273,7 +1273,9 @@ void copyEmplace(S, T)(ref S source, ref T target) @system
12731273
}
12741274
else static if (__traits(hasCopyConstructor, T))
12751275
{
1276-
emplace(cast(Unqual!(T)*) &target); // blit T.init
1276+
// https://issues.dlang.org/show_bug.cgi?id=22766
1277+
import core.internal.lifetime : emplaceInitializer;
1278+
emplaceInitializer(*(cast(Unqual!T*)&target));
12771279
static if (__traits(isNested, T))
12781280
{
12791281
// copy context pointer
@@ -1373,6 +1375,22 @@ void copyEmplace(S, T)(ref S source, ref T target) @system
13731375
static assert(!__traits(compiles, copyEmplace(ss, t)));
13741376
}
13751377

1378+
// https://issues.dlang.org/show_bug.cgi?id=22766
1379+
@system pure nothrow @nogc unittest
1380+
{
1381+
static struct S
1382+
{
1383+
@disable this();
1384+
this(int) @safe pure nothrow @nogc{}
1385+
this(ref const(S) other) @safe pure nothrow @nogc {}
1386+
}
1387+
1388+
S s1 = S(1);
1389+
S s2 = void;
1390+
copyEmplace(s1, s2);
1391+
assert(s2 == S(1));
1392+
}
1393+
13761394
version (DigitalMars) version (X86) version (Posix) version = DMD_X86_Posix;
13771395

13781396
// don't violate immutability for reference types

0 commit comments

Comments
 (0)