Bug 6629 – std.conv.emplace: enforcement is too weak

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
Other
OS
Linux
Creation time
2011-09-08T15:35:00Z
Last change time
2011-09-09T05:53:08Z
Assigned to
nobody
Creator
timon.gehr

Comments

Comment #0 by timon.gehr — 2011-09-08T15:35:28Z
T emplace(T, Args...)(void[] chunk, Args args) if (is(T == class)) { enforce(chunk.length >= __traits(classInstanceSize, T), new ConvException("emplace: chunk size too small")); auto a = cast(size_t) chunk.ptr; enforce(a % T.alignof == 0, text(a, " vs. ", T.alignof)); ... } T.alignof is the alignment of the class reference, not the class instance. Classes have to be 16-byte aligned, but the enforcement checks only for 4 byte alignment. This results in segmentation faults in user code, even though the function performs checks.
Comment #1 by timon.gehr — 2011-09-08T15:58:32Z
Comment #2 by timon.gehr — 2011-09-09T05:04:22Z
The enforcement was actually correct, since apparently alignment of size_t.sizeof is enough.
Comment #3 by timon.gehr — 2011-09-09T05:53:08Z
(In reply to comment #2) > The enforcement was actually correct, since apparently alignment of > size_t.sizeof is enough. It is actually too weak, but enforcing 16-byte alignment is not the correct solution either, see new try at http://d.puremagic.com/issues/show_bug.cgi?id=6635