stdcxx-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Travis Vitek" <>
Subject RE: svn commit: r669735 - in /stdcxx/branches/4.3.x: include/rw/_meta_other.h include/type_traits tests/utilities/20.meta.trans.other.cpp
Date Wed, 25 Jun 2008 21:27:49 GMT

Martin Sebor wrote:
> wrote:
>> Author: vitek
>> Date: Thu Jun 19 15:52:34 2008
>> New Revision: 669735
>> URL:
>> Log:
>> 2008-06-19  Travis Vitek  <>
>> 	STDCXX-926
>> +template <size_t _Size, size_t _Align = 
>>  struct __rw_aligned_storage
>>  {


>>      typedef union {
>> -        unsigned char __data [_Len];
>> -        // not implemented
>> +        unsigned char __size [_Size];
>> +
>> +        typename
>> +        __rw_aligned_storage_impl<_Align>::_C_type __align;
>I believe there are platforms where unions are aligned on
>the boundary given by the first member. This one looks like
>it might be one of them: Unless
>I'm mistaken we should switch the order of the two members
>to make sure the union is properly aligned.

I'm not absolutely sure I'm reading the documentation you linked to
correctly, but here goes...

The first paragraph of that documentation says

Individual members of a union are mapped the same way as members of the
structure. That is, each of the members, if not a union, is mapped as if
it were a member of a structure.  This means that the first storage
locations for each of the members of a union do not overlay each other
if each of the members requires different alignment and therefore
different padding before the beginning of the member.

This violates C99 ( p5)

  As discussed in 6.2.5, a structure is a type consisting
  of a sequence of members, whose storage is allocated in
  an ordered sequence, and a union is a type consisting
  of a sequence of members whose storage overlap.

And ( p14)

  The size of a union is sufficient to contain the largest
  of its members. The value of at most one of the members
  can be stored in a union object at any time. A pointer
  to a union object, suitably converted, points to each of
  its members, and vise versa.

It also voilates C++03 (expr.rel p2)

  If two pointers point to data members of the same union
  object, they compare equal (after conversion to void*,
  if necessary).

Even so, the last paragraph of "Rules for mapping one pair" says

  The pair is now a unit of fixed length and alignment
  requirement, its length is the sum of the two lengths
  plus padding, and its alignment requirement is the
  higher of the two alignment requirements (if they

So the alignment would still be correct as the alignment requirement is
weakest (smallest) for char types, so the alignment that would be used
would be the alignment of the other type.

Please correct me if I'm misinterpreting any of this.


>Also, strictly speaking, names of data members should have
>the _C_ prefix (double underscores are used for locals and
>function parameters).

Agreed. I will fix.


View raw message