Boost C++ Libraries: Ticket #993: Variant should use least common multiple of alignments, rather than maximum https://svn.boost.org/trac10/ticket/993 <p> <strong>Problem</strong>: </p> <p> Reported by Larry Evans on 19 May 2007: </p> <pre class="wiki">The make_storage template at line 215 of: http://boost.cvs.sourceforge.net/boost/boost/boost/variant/variant.hpp?revision=1.97&amp;view=markup uses max over the alignment_of's for the types in the variant (See line2 233-235) to calculate the variant's alignment. However, to handle the extended alignments described on page 3 of: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2165.pdf the boost::math::static_lcm template should be used instead of max. </pre><p> As described in the <a class="ext-link" href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2165.pdf"><span class="icon">​</span>cited document</a>, "alignments have an order from weaker to ... stricter alignments," and "stricter alignments have larger alignment values." </p> <p> But the problem is that "a larger alignment is not necessarily proper alignment for a weaker alignment." Thus taking the maximum alignment does not guarantee that the alignment is proper for types with weaker alignments. </p> <p> <strong>Proposed resolution</strong>: </p> <p> Use the <code>static_lcm</code> template as proposed by Larry. Choosing the least common multiple of all the alignments results in a proper alignment for all of the types because "an alignment requirement is satisfied by [any alignment] that [is] a multiple of it." </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/993 Trac 1.4.3 ebf Thu, 24 May 2007 18:53:01 GMT status, component changed https://svn.boost.org/trac10/ticket/993#comment:1 https://svn.boost.org/trac10/ticket/993#comment:1 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">assigned</span> </li> <li><strong>component</strong> <span class="trac-field-old">None</span> → <span class="trac-field-new">variant</span> </li> </ul> Ticket ebf Fri, 01 Jun 2007 01:20:38 GMT milestone changed https://svn.boost.org/trac10/ticket/993#comment:2 https://svn.boost.org/trac10/ticket/993#comment:2 <ul> <li><strong>milestone</strong> <span class="trac-field-old">Boost 1.34.1</span> → <span class="trac-field-new">Boost 1.35.0</span> </li> </ul> <p> <strong>Further comments</strong>: </p> <p> This fix is not urgently needed: alignments under most (all?) compilers are a power-of-two, in which case the maximum of several alignments is always the least-common multiple. </p> <p> Thus moving this to 1.35 since a fix risks breaking some compilers. </p> Ticket Steven Watanabe Thu, 10 Jun 2010 18:45:16 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/993#comment:3 https://svn.boost.org/trac10/ticket/993#comment:3 <ul> <li><strong>status</strong> <span class="trac-field-old">assigned</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <p> (In <a class="changeset" href="https://svn.boost.org/trac10/changeset/62754" title="Use the least common multiple of alignments instead of the max. Fixes #993">[62754]</a>) Use the least common multiple of alignments instead of the max. Fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/993" title="#993: Bugs: Variant should use least common multiple of alignments, rather than maximum (closed: fixed)">#993</a> </p> Ticket