incubator-stdcxx-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Travis Vitek" <Travis.Vi...@roguewave.com>
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:
>
>vitek@apache.org wrote:
>> Author: vitek
>> Date: Thu Jun 19 15:52:34 2008
>> New Revision: 669735
>> 
>> URL: http://svn.apache.org/viewvc?rev=669735&view=rev
>> Log:
>> 2008-06-19  Travis Vitek  <vitek@roguewave.com>
>> 
>> 	STDCXX-926
>[...]
>> +template <size_t _Size, size_t _Align = 
>>__rw_default_alignment<_Size>::value>
>>  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: http://tinyurl.com/472744. 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 (6.7.2.1 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 (6.7.2.1 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
  differ).

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.

Travis

>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.

>
>Martin
>

Mime
View raw message