Topic: Do unions really get implicit copy assignment operators?


Author: AllanW@my-dejanews.com
Date: 1998/12/10
Raw View
In article <74oqv8$9d8@sis.cambridge.arm.com>,
  scott douglass <sdouglass%_%junk@_.arm.com> wrote:
>     The implicitly-defined copy assignment operator for class X
>     performs memberwise assignment of its subobjects. The direct
>     base classes of X are assigned first, in the order of their
>     declaration in the base-specifier=ADlist, and then the
>     immediate nonstatic data members of X are assigned, in the
>     order in which they were declared in the class definition.
>
> Which requires all members of a union (which overlap) to be assigned.  This
> seems wrong.  Does anyone agree that this is what the standard says and it's a
> defect?

Even if your interpretation is valid, the as-if rule allows the
compiler to omit the intermediate stages -- at least for non-volatile
unions.

> I think that the implicit copy assignment operator for a union should just
> bit-wise copy the whole thing.

Yes, of course.

--
AllanW@my-dejanews.com is a "Spam Magnet" -- never read.
Please reply in USENET only, sorry.

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own


[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]






Author: scott douglass <sdouglass%_%junk@_.arm.com>
Date: 1998/12/10
Raw View
Since unions are a kind of class (9/4) it seems that they must have implicit
copy assignment operators (12.8/10).  The restrictions on union members mean
that their implicit copy assignment operators are _trivial_.  But 12.8/13
doesn't have any special language for unions.  It says:

    The implicitly-defined copy assignment operator for class X performs
memberwise
    assignment of its subobjects. The direct base classes of X are assigned
first,
    in the order of their declaration in the base-specifier=ADlist, and then
the immediate
    nonstatic data members of X are assigned, in the order in which they were
    declared in the class definition.

Which requires all members of a union (which overlap) to be assigned.  This
seems wrong.  Does anyone agree that this is what the standard says and it's a
defect?

I think that the implicit copy assignment operator for a union should just
bit-wise copy the whole thing.


[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]