| 1 |
// REQUIRED_ARGS: -preview=fieldwise -O |
| 2 |
// https://issues.dlang.org/show_bug.cgi?id=21821 |
| 3 |
|
| 4 |
// test case comes from unittests in core.lifetime |
| 5 |
|
| 6 |
void test() |
| 7 |
{ |
| 8 |
alias T = immutable(S); |
| 9 |
T source; |
| 10 |
T target; |
| 11 |
copyEmplacex(source, target); |
| 12 |
T expectedCopy = source; |
| 13 |
assert(target == expectedCopy); |
| 14 |
} |
| 15 |
|
| 16 |
struct S |
| 17 |
{ |
| 18 |
int x = 42; |
| 19 |
this(this) { x += 10; } |
| 20 |
} |
| 21 |
|
| 22 |
void copyEmplacex(ref immutable(S) source, ref immutable(S) target) @system |
| 23 |
{ |
| 24 |
import core.stdc.string : memcpy; |
| 25 |
memcpy(cast(S*) &target, cast(S*) &source, S.sizeof); |
| 26 |
(cast() target).__xpostblit(); // casting away immutable |
| 27 |
} |
| 28 |
|
| 29 |
void main() |
| 30 |
{ |
| 31 |
test(); |
| 32 |
} |