This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Undefined behavior due to 6.5.16.1p3


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)


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]