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)?
Wouldn't it be safer to use alignof(_Tp2::_M_t) here?
Though, apparently that is a GNU extension, so you'd need to use __alignof__
instead.
Jakub