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

          Issue ID: 22219
           Summary: core.lifetime emplace is unsafe with void[] override
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P1
         Component: druntime
          Assignee: [email protected]
          Reporter: [email protected]

The emplace function is safety checking for both the length and alignment
before casting to the requested type, allowing the cast to be safe.

---
import core.lifetime;

void main() @safe
{
    ubyte[int.sizeof] buf = void;
    auto i = emplace!int(buf, 4); // fails
}
---

workaround:
---
import core.lifetime;

void main() @safe
{
    ubyte[int.sizeof] tmp = void;
    auto buf = (() @trusted => cast(int*)(tmp.ptr))();
    auto i = emplace(buf, 4); // uses the T* variant
}
---

--

Reply via email to