[Issue 22552] New: moveEmplace wipes context pointer of nested struct contained in non-nested struct
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Mon Nov 29 19:07:19 UTC 2021
https://issues.dlang.org/show_bug.cgi?id=22552
Issue ID: 22552
Summary: moveEmplace wipes context pointer of nested struct
contained in non-nested struct
Product: D
Version: D2
Hardware: All
OS: All
Status: NEW
Severity: normal
Priority: P1
Component: druntime
Assignee: nobody at puremagic.com
Reporter: stanislav.blinov at gmail.com
import core.lifetime;
void main()
{
int i;
struct Nested
{
~this() { ++i; }
}
static struct NotNested
{
Nested n;
}
auto a = NotNested(Nested()); // when this is destructed things go boom...
NotNested b = void;
moveEmplace(a, b); // ...because this wipes context pointer in a.n
} // segmentation fault
---
That's because moveEmplace simply blits NotNested.init into a. Instead it
probably should move things fieldwise and avoid wiping context pointers in
fields that are nested structs.
--
More information about the Digitalmars-d-bugs
mailing list