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

Commit c7d5a22

Browse files
tchaloupkaRazvanN7
authored andcommitted
Fix issue 22336 - betterC move of non zero structs
Co-authored-by: Razvan Nitu <[email protected]>
1 parent 9012401 commit c7d5a22

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

src/core/lifetime.d

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2124,7 +2124,9 @@ private void moveEmplaceImpl(T)(scope ref T target, return scope ref T source)
21242124
() @trusted { memset(&source, 0, sz); }();
21252125
else
21262126
{
2127-
auto init = typeid(T).initializer();
2127+
import core.internal.lifetime : emplaceInitializer;
2128+
ubyte[T.sizeof] init = void;
2129+
emplaceInitializer(*(() @trusted { return cast(T*)init.ptr; }()));
21282130
() @trusted { memcpy(&source, init.ptr, sz); }();
21292131
}
21302132
}

test/betterc/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
include ../common.mak
22

3-
TESTS:=test18828 test19416 test19421 test19561 test20088 test20613 test19924
3+
TESTS:=test18828 test19416 test19421 test19561 test20088 test20613 test19924 test22336
44

55
.PHONY: all clean
66
all: $(addprefix $(ROOT)/,$(addsuffix ,$(TESTS))) $(addprefix $(ROOT)/,test19924.done)

test/betterc/src/test22336.d

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*******************************************/
2+
// https://issues.dlang.org/show_bug.cgi?id=22336
3+
4+
import core.lifetime;
5+
6+
struct Foo {
7+
int f = -1;
8+
@disable this(this);
9+
this(int x) { f = x; }
10+
@disable this();
11+
}
12+
13+
extern(C) int main() {
14+
Foo a = Foo(42);
15+
Foo b = move(a);
16+
assert(a.f == -1);
17+
assert(b.f == 42);
18+
return 0;
19+
}

0 commit comments

Comments
 (0)