Title
Question on copy constructor elision example
Status
cd1
Section
6.7.7 [class.temporary]
Submitter
Steve Clamage

Created on 2001-11-02.00:00:00 last changed 162 months ago

Messages

Date: 2005-04-15.00:00:00

[Voted into WP at April 2005 meeting.]

Date: 2004-10-15.00:00:00

Proposed resolution (October, 2004):

In 6.7.7 [class.temporary] paragraph 2, change the last sentence as indicated:

On the other hand, the expression a=f(a) requires a temporary for either the argument a or the result of f(a) to avoid undesired aliasing of a the result of f(a), which is then assigned to a.
Date: 2020-12-15.00:00:00

Section 6.7.7 [class.temporary] paragraph 2, abridged:

  X f(X);
  void g()
  {
	X a;
	a = f(a);
  }

a=f(a) requires a temporary for either the argument a or the result of f(a) to avoid undesired aliasing of a.

The note seems to imply that an implementation is allowed to omit copying "a" to f's formal argument, or to omit using a temporary for the return value of f. I don't find that license in normative text.

Function f returns an X by value, and in the expression the value is assigned (not copy-constructed) to "a". I don't see how that temporary can be omitted. (See also _N4750_.15.8 [class.copy] p 15)

Since "a" is an lvalue and not a temporary, I don't see how copying "a" to f's formal parameter can be avoided.

Am I missing something, or is 6.7.7 [class.temporary] p 2 misleading?

History
Date User Action Args
2008-10-05 00:00:00adminsetstatus: wp -> cd1
2005-10-22 00:00:00adminsetstatus: dr -> wp
2005-05-01 00:00:00adminsetmessages: + msg1194
2005-05-01 00:00:00adminsetstatus: ready -> dr
2004-11-07 00:00:00adminsetmessages: + msg1048
2004-11-07 00:00:00adminsetstatus: open -> ready
2001-11-02 00:00:00admincreate