www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 22219] New: core.lifetime emplace is unsafe with void[]

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: nobody puremagic.com
          Reporter: jlourenco5691 gmail.com

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
}
---

--
Aug 16 2021