Opened 15 years ago

Closed 12 years ago

#993 closed Bugs (fixed)

Variant should use least common multiple of alignments, rather than maximum

Reported by: ebf Owned by: ebf
Milestone: Boost 1.36.0 Component: variant
Version: Severity: Problem
Keywords: Cc:

Description

Problem:

Reported by Larry Evans on 19 May 2007:

The make_storage template at line 215 of:

http://boost.cvs.sourceforge.net/boost/boost/boost/variant/variant.hpp?revision=1.97&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.

As described in the cited document, "alignments have an order from weaker to ... stricter alignments," and "stricter alignments have larger alignment values."

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.

Proposed resolution:

Use the static_lcm 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."

Change History (3)

comment:1 by ebf, 15 years ago

Component: Nonevariant
Status: newassigned

comment:2 by ebf, 15 years ago

Milestone: Boost 1.34.1Boost 1.35.0

Further comments:

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.

Thus moving this to 1.35 since a fix risks breaking some compilers.

comment:3 by Steven Watanabe, 12 years ago

Resolution: fixed
Status: assignedclosed

(In [62754]) Use the least common multiple of alignments instead of the max. Fixes #993

Note: See TracTickets for help on using tickets.