This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Re: [PATCH] Canonical types (1/3)

On 12/5/06, Paolo Carlini <> wrote:
At the risk of being of topic, and vague, I'd like to remind Doug and
all the interested people that, talking about C++0x, we have the open
issue C++/19163, which, among other things, blocks a general, fully
conforming, implementation of the alignment traits. If someone, among
the knowledgeable people, can start giving some thought to the issue it
would be great (*)...

There's an alignment proposal coming down the pipe for C++0x:

The paper is "blessed by Evolution" but has not yet gone through core.
I haven't been involved at all, but from reading the paper it seems
that the interaction with the type system (especially templates) is
rather underspecified for our purposes. Too bad :(
I do see that the "alignas" specifier takes a constant-expression, so
it should work with templates in the obvious way.

What was wrong with that patch to 19163, anyway? Browsing the
archives, I don't see a reason for its rejection...

Anyway, even with a fix for 19163, you still need to enumerate all of
the possible alignment values, right? If so, then there is a
workaround for TR1/C++0x aligned_storage. GCC handles alignment
properly on class types, so Boost uses this little hack to make its
"type_with_alignment" trait work:

 namespace align {
 struct __attribute__((__aligned__(2))) a2 {};
 struct __attribute__((__aligned__(4))) a4 {};
 struct __attribute__((__aligned__(8))) a8 {};
 struct __attribute__((__aligned__(16))) a16 {};
 struct __attribute__((__aligned__(32))) a32 {};

 template<> class type_with_alignment<1>  { public: typedef char type; };
 template<> class type_with_alignment<2>  { public: typedef align::a2 type; };
 template<> class type_with_alignment<4>  { public: typedef align::a4 type; };
 template<> class type_with_alignment<8>  { public: typedef align::a8 type; };
 template<> class type_with_alignment<16> { public: typedef align::a16 type; };
 template<> class type_with_alignment<32> { public: typedef align::a32 type; };

Create a union of type_with_alignment<N>::type and a character array
of the right length, and you have TR1/C++0x's aligned_storage.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]