Bug 6635 – 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-09T05:35:00Z
Last change time
2015-06-09T05:14:52Z
Assigned to
verylonglogin.reg
Creator
timon.gehr

Comments

Comment #0 by timon.gehr — 2011-09-09T05:35:09Z
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, always equal to size_t.sizeof, not the alignment of the class instance. A class instance can require a larger alignment in some cases, eg. if it has fields with larger alignments.
Comment #1 by andrei — 2011-12-16T15:34:12Z
Actually I think this is incidentally fine (at least for dmd) because a class in dmd always starts with a pointer. Subsequent fields, in case they do require a larger alignment, would insert a gap.
Comment #2 by timon.gehr — 2011-12-16T15:40:09Z
Type_Info vptr: 4 bytes gap: 4 bytes ulong foo; 8 bytes (requires alignment of 8) If the class is emplaced at an address that is an odd multiple of four, then foo will be misaligned.
Comment #3 by verylonglogin.reg — 2012-10-26T09:22:09Z
Comment #4 by github-bugzilla — 2012-12-12T07:41:17Z