From -2203539693780006673
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,f5d433881cc29cff
X-Google-Attributes: gidf78e5,public
From: jpotter@falcon.lhup.edu (John Potter)
Subject: Named return value optimisation- reprise.
Date: 1997/06/19
Message-ID: <199706191728.MAA04926@csrlink.net>#1/1
X-Deja-AN: 251133755
X-Original-Date: Thu, 19 Jun 1997 16:35:50 GMT
Organization: -
X-Auth: PGPMoose V1.1 PGP comp.std.c++ iQBVAwUBM6lePky4NqrwXLNJAQGqyAIAzf4E9auPrqxCgiXFXx6jcdcl1UXDRICV bsfw+8gK15vqOZWVHcySCoE1h1k1ditZd7JAJHCgdkxIiBe2OMaZgw== =6AGp
Newsgroups: comp.std.c++
Originator: austern@isolde.mti.sgi.com


On 18 Jun 97 02:15:53 GMT, Jason Merrill <jason@cygnus.com> wrote:

: >>>>> Brian Parker <bparker@gil.com.au> writes:

: > Trouble is, the STL also plays aliasing games. In fact, many classes
: > using dynamically allocated memory would fall prey to the 12.8/5 bugs.
: >  I repeat here a previously posted example using STL (it involves
: > 12.8/5 being used to elide the copy on pass-by-value).

: In this testcase, the problem occurs because even though 'v' is not
: directly used after the call, references to data it controls are.  This
: would not be a problem if 'v' went out of scope immediately after the
: call, because any references to its data are undefined after it goes out of
: scope.  Thus, I suggest that 12.8/15 should be reworded to read 

: 15Whenever an automatic (_basic.stc.auto_) class object is copied and the
:   original object and the copy have the same type, and the block containing
:   the original object exits (_stmt.jump_) immediately after the copy is
:   created, an implementation is permitted to treat the original and the
:   copy as two different ways of referring to the same object and not
:   perform a copy at all.  In that case, the object is destroyed when the
:   copy would have been destroyed without the optimization.

: I think this only allows the RVO.

It clearly requires a copy for g(t2).  Not so sure about f(t1).  The
wording does force an unused copy to be made.  Did you intend that?  I
am not worried about it since I did not expect to get this anyway.  It
would be nice to have an example which does work.
	Thing h (Thing t) {
		Thing tmp(t);
		// maybe do something with tmp
		return tmp;
		}
Here tmp can be removed and the return value used in place of tmp with
no copy.

It is also simple to disable by doing what many people recommend
anyway and make the return a Thing const.  Then the types are not the
same.

John
---
[ comp.std.c++ is moderated.  To submit articles: Try just posting with your 
                newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  Comments? mailto:std-c++-request@ncar.ucar.edu 
]



