This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Undefined behavior due to 6.5.16.1p3
- From: Vincent Lefevre <vincent+gcc at vinc17 dot org>
- To: gcc at gcc dot gnu dot org
- Date: Thu, 12 Mar 2015 10:01:51 +0100
- Subject: Re: Undefined behavior due to 6.5.16.1p3
- Authentication-results: sourceware.org; auth=none
- References: <54FF2182 dot 1090800 at robbertkrebbers dot nl> <alpine dot DEB dot 2 dot 10 dot 1503102153590 dot 10726 at digraph dot polyomino dot org dot uk> <550042BD dot 8000608 at robbertkrebbers dot nl> <20150311160815 dot GA2967 at ypig dot lip dot ens-lyon dot fr> <20150311161155 dot GM1746 at tucnak dot redhat dot com> <20150311163101 dot GA4384 at ypig dot lip dot ens-lyon dot fr> <20150311163931 dot GN1746 at tucnak dot redhat dot com> <20150311165601 dot GB4384 at ypig dot lip dot ens-lyon dot fr> <20150311170208 dot GA6467 at ypig dot lip dot ens-lyon dot fr> <alpine dot DEB dot 2 dot 10 dot 1503120105030 dot 24073 at digraph dot polyomino dot org dot uk>
On 2015-03-12 01:05:42 +0000, Joseph Myers wrote:
> On Wed, 11 Mar 2015, Vincent Lefevre wrote:
>
> > BTW, the following is forbidden (and makes no sense), but is accepted
> > by GCC without a warning:
> >
> > int foo (void)
> > {
> > union { char a[8]; int b; } u = { .a = { 0 }, .b = 1 };
> > return u.b;
> > }
>
> What constraint do you think forbids it? It looks like an ordinary case
> of overriding with designated initializers.
It seems that the standard doesn't specify the behavior.
Concerning the override, I could only see 6.7.9p19, which says:
The initialization shall occur in initializer list order, each
initializer provided for a particular subobject overriding any
previously listed initializer for the same subobject;151)
but in the case of a union, .a and .b are not the same subobject
since they don't have the same type (and not necessarily the same
size).
--
Vincent Lefèvre <vincent@vinc17.net> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)