On Fri, Feb 16, 2018 at 02:14:09PM -0700, Martin Sebor wrote:
> On 02/16/2018 01:44 PM, Jakub Jelinek wrote:
> > On Fri, Feb 16, 2018 at 09:25:30PM +0100, Richard Biener wrote:
> > > But the broken compilers will overwrite the memset data with possibly 
> > > uninitialized fields of a TARGET_EXPR.
> > 
> > Perhaps for hash-table.h we could use:
> > #ifndef BROKEN_VALUE_INITIALIZATION
> >       for ( ; size; ++entries, --size)
> >     *entries = value_type ();
> > #else
> >       union U { char c[sizeof (value_type)]; value_type v; } u;
> 
> In C++ 98 a type with a constructor cannot be a member of a union
> so the above wouldn't be valid but if I understand what you're
> trying to do you don't need the member.  All you need is a buffer.
> Something like this?
> 
>   char __attribute__ ((aligned (__alignof__ (value_type))))
>   buf [sizeof (value_type)] = "";
>   value_type *p = new (buf) value_type ();

Rather
    for ( ; size; ++entries, --size)
      *entries = *p;
    p->~value_type ();

I was trying to avoid the __aligned__ attribute and __alignof__, but
I guess we could guard that with GCC_VERSION >= 2000 or something similar,
after all, the documented minimum is GCC 3.4 I think.

>   *entries = *p;
>   p->value_type ();
> 
> I have no idea if this gets around the bug.

        Jakub

Reply via email to