[Issue 17448] Move semantics cause memory corruption and cryptic bugs

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon May 30 05:58:57 UTC 2022


https://issues.dlang.org/show_bug.cgi?id=17448

--- Comment #44 from Eyal <eyal at weka.io> ---
Hi Steven, thanks for reaching out.

This example still fails on newest dmd:

    struct S {
        S* addr;
        this(int dummy) { this.addr = &this; }
        static S create() { return S(1); }
    }

    unittest {
        auto s1 = S(1);
        assert(s1.addr == &s1);
        auto s2 = S.create();
        assert(s2.addr == &s2); // <-- fails
    }


While "@safe" disallows it, it also prevents all use of '&' here, so it is not
really a practical option for such code.

--


More information about the Digitalmars-d-bugs mailing list