[patch] libstdc++/66017 Avoid bad casts and fix alignment of _Rb_tree_node<long long>::_M_storage
Jonathan Wakely
jwakely@redhat.com
Fri May 22 15:19:00 GMT 2015
On 22/05/15 16:29 +0200, Jakub Jelinek wrote:
>On Fri, May 22, 2015 at 03:15:10PM +0100, Jonathan Wakely wrote:
>> --- a/libstdc++-v3/include/ext/aligned_buffer.h
>> +++ b/libstdc++-v3/include/ext/aligned_buffer.h
>> @@ -31,21 +31,23 @@
>>
>> #pragma GCC system_header
>>
>> -#if __cplusplus >= 201103L
>> -# include <type_traits>
>> -#else
>> +#if __cplusplus < 201103L
>> # include <bits/c++0x_warning.h>
>> #endif
>>
>> +#include <cstddef>
>> +
>> namespace __gnu_cxx
>> {
>> template<typename _Tp>
>> struct __aligned_buffer
>> - : std::aligned_storage<sizeof(_Tp), std::alignment_of<_Tp>::value>
>> {
>> - typename
>> - std::aligned_storage<sizeof(_Tp), std::alignment_of<_Tp>::value>::type
>> - _M_storage;
>> + // Target macro ADJUST_FIELD_ALIGN can produce different alignment for
>> + // types when used as class members. __aligned_buffer is intended for
>> + // use as a class member, so align the buffer as for a class member.
>> + struct _Tp2 { _Tp _M_t; };
>> +
>> + alignas(alignof(_Tp2)) unsigned char _M_storage[sizeof(_Tp)];
>
>Is alignof(_Tp2) always the same as alignof(_Tp2::_M_t) on all targets
>(I mean, won't some target align the structure more than its only field)?
Hmm, maybe. I don't know.
>Wouldn't it be safer to use alignof(_Tp2::_M_t) here?
Yes.
>Though, apparently that is a GNU extension, so you'd need to use __alignof__
>instead.
Yes, that's what I did in an earlier version of the patch, so I'll go
back to that.
More information about the Gcc-patches
mailing list