On Thu, Aug 13, 2020 at 02:25:42PM +0200, Jakub Jelinek via Gcc-patches wrote:
> --- gcc/vec.h.jj      2020-08-12 12:45:58.410686880 +0200
> +++ gcc/vec.h 2020-08-13 14:18:06.967041880 +0200
> @@ -1281,10 +1281,11 @@ template<typename T, typename A>
>  inline size_t
>  vec<T, A, vl_embed>::embedded_size (unsigned alloc)
>  {
> -  struct alignas (T) U { char data[sizeof (T)]; };
> +  struct V { char a; T b; } *v;
> +  struct alignas (alignof (v->b)) U { char data[sizeof (T)]; };
>    typedef vec<U, A, vl_embed> vec_embedded;
> -  static_assert (sizeof (vec_embedded) == sizeof(vec), "");
> -  static_assert (alignof (vec_embedded) == alignof(vec), "");
> +  static_assert (sizeof (vec_embedded) == sizeof (vec), "");
> +  static_assert (alignof (vec_embedded) == alignof (vec), "");
>    return offsetof (vec_embedded, m_vecdata) + alloc * sizeof (T);
>  }
>  

I guess this version is better.  Or maybe we should use the old
embedded_size version with offsetof for std::is_standard_layout (T)
and only use the new one (and in that case we don't need hacks like this
otherwise)?

        Jakub

Reply via email to