Topic: Defect report: handling of reference members not specified in implicit


Author: kanze@gabi-soft.fr
Date: Mon, 20 Jun 2005 15:34:00 +0000 (UTC)
Raw View
Ben Hutchings wrote:
> <tpochep@mail.ru> wrote:
> <snip>
> > Clause 12 (12.8/8) says:

> > The implicitly-defined copy constructor for class X performs a
> > memberwise copy of its subobjects. The
> > order of copying is the same as the order of initialization of bases
> > and members in a user-defined constructor
> > (see 12.6.2). Each subobject is copied in the manner appropriate to its
> > type:
> > - if the subobject is of class type, the copy constructor for the
> > class is used;
> > - if the subobject is an array, each element is copied, in the manner
> > appropriate to the element type;
> > - if the subobject is of scalar type, the built-in assignment
> > operator is used.
> > Virtual base class subobjects shall be copied only once by the
> > implicitly-defined copy constructor (see
> > 12.6.2).

> > What about references?
> > AFAIK references are not scalar types.

> Nor are they objects!

Nor are they mentionned in the above paragraph.

> > Should I explicitly declare copy ctor? Or compiler-generated
> > is everywhere (everywhere == all implementations) good?

> The implicitly-defined copy constructor will copy members of
> reference type along with the other members.  I'm not aware of
> any implementations that fail to do this.

I think the original poster has a point.  All of the
implementations I know do copy initialize member references, and
I can't imagine that anything else was intended.  But what the
standard actually says is that "the implicitly-defined copy
constructor for class X performs a memberwise copy of its
subobjects."  References aren't objects; can they be subobjects?
If not, then the standard doesn't say what an implementation
should do with them, and when the standard doesn't specify
something, it's undefined behavior.

I suspect that this is a defect in the standard.  Minor, since
we all know what is wanted (and all implementations seem to
agree with us), but technically a defect.  The first sentence
should probably read "[...] a memberwise copy of its subobjects
and members of reference type," and there should be an
additional point for references.

I've added comp.std.c++ to the groups.

--
James Kanze                                           GABI Software
Conseils en informatique orient   e objet/
                    Beratung in objektorientierter Datenverarbeitung
9 place S   mard, 78210 St.-Cyr-l'   cole, France, +33 (0)1 30 23 00 34


      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

[ 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://www.jamesd.demon.co.uk/csc/faq.html                       ]