D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 6629 - std.conv.emplace: enforcement is too weak
Summary: std.conv.emplace: enforcement is too weak
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: Other Linux
: P2 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-09-08 15:35 UTC by timon.gehr
Modified: 2011-09-09 05:53 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description timon.gehr 2011-09-08 15:35:28 UTC
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 2 timon.gehr 2011-09-09 05:04:22 UTC
The enforcement was actually correct, since apparently alignment of size_t.sizeof is enough.
Comment 3 timon.gehr 2011-09-09 05:53:08 UTC
(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