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

Commit cc4b3e1

Browse files
committed
Fix Issue 20767 - __move_post_blt must only recursively call itself on a struct's fields not all members [DIP1014]
1 parent e71d88c commit cc4b3e1

File tree

1 file changed

+27
-3
lines changed

1 file changed

+27
-3
lines changed

src/core/internal/moving.d

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ Note:
2929
void __move_post_blt(S)(ref S newLocation, ref S oldLocation) nothrow
3030
if (is(S == struct))
3131
{
32-
static foreach (memberName; __traits(allMembers, S))
32+
static foreach (i, M; typeof(S.tupleof))
3333
{
34-
static if (is(typeof(__traits(getMember, S, memberName)) == struct))
34+
static if (is(M == struct))
3535
{
36-
__move_post_blt(__traits(getMember, newLocation, memberName), __traits(getMember, oldLocation, memberName));
36+
__move_post_blt(newLocation.tupleof[i], oldLocation.tupleof[i]);
3737
}
3838
}
3939

@@ -87,3 +87,27 @@ void __move_post_blt(S)(ref S newLocation, ref S oldLocation) nothrow
8787
__move_post_blt(dest, src);
8888
assert(dest.movedInto && dest.a.movedInto);
8989
}
90+
91+
@safe nothrow unittest
92+
{
93+
static struct DoNotMove
94+
{
95+
bool movedInto;
96+
void opPostMove(const ref DoNotMove oldLocation)
97+
{
98+
movedInto = true;
99+
}
100+
}
101+
static DoNotMove doNotMove;
102+
103+
struct A
104+
{
105+
@property ref DoNotMove member()
106+
{
107+
return doNotMove;
108+
}
109+
}
110+
A src, dest;
111+
__move_post_blt(dest, src);
112+
assert(!doNotMove.movedInto);
113+
}

0 commit comments

Comments
 (0)