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: bug in GCC or C++ standard ?


On 12/11/2008, James Dennett <james.dennett@gmail.com> wrote:
> In a union only one field can be active at one time, hence
> initializing more than one makes no sense
> ...
> However, const items need to be initialized, hence potting two in a
> union makes no sense.

Conceptually there is nothing wrong with having two or more const
members in a union.  The compiler (or standard) should recognise this
particular case, and interpret that initialising one member of a union
is equivalent to initialising all the members, be they const or not.

> (The standard doesn't need an explicit rule to say that, as it's
> implied by other rules.)

I'm not sure I agree with the standard.  The two requirements, i.e.
(i) need to initialise all consts, and (ii) only one member of a union
can be initialised, are at conflict with each other. Requirement (ii)
fullfills requirement (i), so the compiler shouldn't be complaining
about uninitialised consts.


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