Thread overview
[Issue 6635] New: std.conv.emplace: enforcement is too weak
Sep 09, 2011
timon.gehr@gmx.ch
Dec 16, 2011
timon.gehr@gmx.ch
Oct 26, 2012
Denis Shelomovskij
Feb 05, 2013
Andrej Mitrovic
September 09, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=6635

           Summary: std.conv.emplace: enforcement is too weak
           Product: D
           Version: unspecified
          Platform: Other
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: nobody@puremagic.com
        ReportedBy: timon.gehr@gmx.ch


--- Comment #0 from timon.gehr@gmx.ch 2011-09-09 05:35:09 PDT ---
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.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
December 16, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=6635


Andrei Alexandrescu <andrei@metalanguage.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |andrei@metalanguage.com


--- Comment #1 from Andrei Alexandrescu <andrei@metalanguage.com> 2011-12-16 15:34:12 PST ---
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.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
December 16, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=6635



--- Comment #2 from timon.gehr@gmx.ch 2011-12-16 15:40:09 PST ---
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.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
October 26, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=6635


Denis Shelomovskij <verylonglogin.reg@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
                 CC|                            |verylonglogin.reg@gmail.com
         AssignedTo|nobody@puremagic.com        |verylonglogin.reg@gmail.com


--- Comment #3 from Denis Shelomovskij <verylonglogin.reg@gmail.com> 2012-10-26 20:22:09 MSD ---
Fixed in pull 896: https://github.com/D-Programming-Language/phobos/pull/896

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
December 12, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=6635



--- Comment #4 from github-bugzilla@puremagic.com 2012-12-12 07:41:17 PST ---
Commit pushed to master at https://github.com/D-Programming-Language/phobos

https://github.com/D-Programming-Language/phobos/commit/4bc219451bac54d1b61e14ecd3e3dd2bdcd6c419 Fix Issue 6635 - std.conv.emplace: enforcement is too weak

* Issue URL: http://d.puremagic.com/issues/show_bug.cgi?id=6635

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
February 05, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=6635


Andrej Mitrovic <andrej.mitrovich@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
                 CC|                            |andrej.mitrovich@gmail.com
         Resolution|                            |FIXED


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------