[cfe-dev] question about initializing multiple members of unions

Richard Smith richard at metafoo.co.uk
Mon Sep 16 15:28:05 PDT 2013


On Mon, Sep 16, 2013 at 2:21 PM, Gao, Yunzhong <
yunzhong_gao at playstation.sony.com> wrote:

> > How can it give that result? agg_instance.a.zero and agg_instance.a.two
> were never initialized.
>
> I guess I see your point. I was just not comfortable with having
> unspecified values in the end result of an
> initializer list; my interpretation of 6.7.9p19 is that they all should be
> initialized to something. But unions are
> special since you also have to apply 6.2.6.1p7.
>
> Well, if a.zero and a.two were not initialized, and if I apply 6.7.9p19,
> they should be initialized to zero, right?
> And a.one will be initialized to 1. The end result will be {0, 1, 0, 3} ?
>

Yes, with that interpretation, that seems like a possible conclusion, even
though it's a bit weird. That's not the same as the interpretation that
Matthew Curtis was suggesting ("same as a series of assignments") though,
which was the one which led to {unspecified, unspecified, unspecified, 3}.

I still think Eli's approach is the right one here.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20130916/a739661e/attachment.html>


More information about the cfe-dev mailing list