Topic: Interpretation of 12.8


Author: rwhand@NOSPAMoperamail.com (Robert W Hand)
Date: Thu, 14 Nov 2002 02:19:26 +0000 (UTC)
Raw View
I have a question about the interpretation of subclause 12.8,
paragraphs 5 and 10.  These two paragraphs specify the form of the
parameter for an implicitly defined class copy constructor and class
copy assignment operator, respectively.

In both paragraphs, the specification depends upon a series of
conditional clauses proceeded by the word "if".  For example, the
parameter for an implicitly defined assignment operator for class X
will be const X&

"if

 - each direct base class B has a copy assignment operator whose
parameter is of type const B&, const volatile B& or B, and

 - for all the nonstatic data members of X that are of a class type
M(or array thereof), each such class type has a copy assignment
operator whose parameter is of type const M&, const volatile M& or M."

Otherwise the parameter of the assignment operator will be X&.  (There
is an obvious typo in that the words "copy constructor" is used here.)

The copy constructor paragraph reads very similarly with the omission
of the impossible parameters M and B and the inclusion of virtual base
classes.

What happens if class X has no direct base classes and no nonstatic
data members that are of class type, a rather common occurrence?  The
two conditional clauses are empty of meaning.  How are we to interpret
such a situation?  Does that mean that the implicitly defined copy
assignment operator (or copy constructor) for such a class has a
parameter of X&?

There are two other subclauses that are somewhat pertinent.  Subclause
13.5.3 is another subclause that is about overloading the copy
assignment operator.  But it really does not help.  Subclause 13.6
implies that for promoted arithmetic types, that the right hand
parameter will be of type R.  So it really does not help either.

I am reminded of a time that my friend Georgie told me,

"A car is a good one if the tires have white sidewalls."

As it happened, later that day, Georgie and I were walking through a
car junkyard.  I spied an old car without tires or engine.  You
probably guessed it, I asked Georgie if the car was a good one.  Well,
Georgie thought about it for a long time.  He could not decide because
there were no tires.  The lack of an engine did not seem to faze him.
So he hunted around and found some old tires with white sidewalls
lying around the junkyard.  He put those tires on that car, turned to
me, and said, "It's a good car now." :-)

It seems to me that the default parameter should be const X& so that
assignment of a constant object of type X can be made to a
non-constant object of type X, unless the assignment operators of the
base or data members have the non-constant form.  But does the
standard say that somewhere?  Thanks in advance.

Best wishes,

Bob

---
[ 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                       ]





Author: ark@research.att.com (Andrew Koenig)
Date: Thu, 14 Nov 2002 07:22:22 +0000 (UTC)
Raw View
Robert> In both paragraphs, the specification depends upon a series of
Robert> conditional clauses proceeded by the word "if".  For example, the
Robert> parameter for an implicitly defined assignment operator for class X
Robert> will be const X&

Robert> "if

Robert>  - each direct base class B has a copy assignment operator whose
Robert> parameter is of type const B&, const volatile B& or B, and

Robert>  - for all the nonstatic data members of X that are of a class type
Robert> M(or array thereof), each such class type has a copy assignment
Robert> operator whose parameter is of type const M&, const volatile M& or M."

Robert> Otherwise the parameter of the assignment operator will be X&.  (There
Robert> is an obvious typo in that the words "copy constructor" is used here.)

Robert> The copy constructor paragraph reads very similarly with the omission
Robert> of the impossible parameters M and B and the inclusion of virtual base
Robert> classes.

Robert> What happens if class X has no direct base classes and no
Robert> nonstatic data members that are of class type, a rather common
Robert> occurrence?  The two conditional clauses are empty of meaning.
Robert> How are we to interpret such a situation?  Does that mean that
Robert> the implicitly defined copy assignment operator (or copy
Robert> constructor) for such a class has a parameter of X&?

If class X has no direct base classes, then every direct base class of
X satisfies every condition that you can imagine.

--
Andrew Koenig, ark@research.att.com, http://www.research.att.com/info/ark

---
[ 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                       ]