stdcxx-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Travis Vitek" <>
Subject RE: question about aligned_storage
Date Thu, 26 Jun 2008 19:46:27 GMT

>Martin Sebor wrote:
>Travis Vitek wrote:
>> I could implement the specializations of the helper for all possible
>> values up to the upper limit and then let the compiler puke when it
>> can't honor the alignment that was requested. It is not 
>'difficult' to
>> do this, I just don't see it as useful because I can't test 
>them until I
>> have at least one compier that supports the ability to do
>> non-power-of-two alignments.
>That was another question I was going to ask although I think I know
>the answer already: the specialization is only necessary for "crappy
>compilers" ;-) that require N to be a literal in
>__attribute__((aligned(N))), right? If so, I suggest providing the
>specializations only for these, shall we say, "limited" compilers
>and defining the primary template using the non-type template
>parameter N for the rest.


>>>> The following code is very similar to that typical
>>>> implementation, but it does not compile because value passed to the
>>>> aligned attribute has to be a literal, not a constant expression.
>>> That's what you for using a crappy compiler ;-) It compiles
>>> with gcc. See
>> Uh, yeah, it compiles...
>>> but watch out for:
>> but it is utterly useless because of this bug. You can't use 
>> the nested aligned type. Talk about crappy compilers.
>It isn't completely useless because the attribute can successfully
>be applied to data members with the same result:
>     template <int N>
>     struct A {
>         struct S {
>             short f[3]; __attribute__ ((aligned (N)));
>         };
>     };

Here is a testcase...

  $ cat z.cpp && g++ --version && g++ -c z.cpp

  template <int N, int A>
  struct __rw_aligned_storage { 
      typedef struct {
          char _C_align [N] __attribute__ ((aligned (A)));
      } type;

  __rw_aligned_storage<10, 4>::type aligned_t;

  g++ (GCC) 4.3.1
  Copyright (C) 2008 Free Software Foundation, Inc.
  This is free software; see the source for copying conditions.  There
is NO

  z.cpp: In instantiation of '__rw_aligned_storage<10, 4>::type':
  z.cpp:9:   instantiated from here
  z.cpp:5: error: requested alignment is not a constant

If I can't access the member type 'type', then the feature is useless.
The nested type is the only thing that is aligned. If you are sure that
this will work with gcc-4.3, please show me where I've gone wrong.


>>> We should open an enhancement request with Microsoft.
>> I'll do that.
>>> Martin

View raw message