www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 22552] New: moveEmplace wipes context pointer of nested


          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 puremagic.com
          Reporter: stanislav.blinov 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.

Nov 29 2021