This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: [patch] libstdc++/66017 Avoid bad casts and fix alignment of _Rb_tree_node<long long>::_M_storage
- From: Jakub Jelinek <jakub at redhat dot com>
- To: Jonathan Wakely <jwakely at redhat dot com>, Jason Merrill <jason at redhat dot com>
- Cc: libstdc++ at gcc dot gnu dot org, gcc-patches at gcc dot gnu dot org
- Date: Fri, 22 May 2015 16:29:44 +0200
- Subject: Re: [patch] libstdc++/66017 Avoid bad casts and fix alignment of _Rb_tree_node<long long>::_M_storage
- Authentication-results: sourceware.org; auth=none
- References: <20150522141510 dot GN30202 at redhat dot com>
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
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