From -782287096994093926
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,f5d433881cc29cff
X-Google-Attributes: gidf78e5,public
From: bparker@gil.com.au (Brian Parker)
Subject: Re: Named return value optimisation- reprise.
Date: 1997/06/23
Message-ID: <33ab49d6.3482939@news.ipswich.gil.com.au>#1/1
X-Deja-AN: 252085406
References: <33a345bf.7425526@news.ipswich.gil.com.au> <33A478C1.329@acm.org> <u9pvtnuemu.fsf@yorick.cygnus.com> <33a5f9a1.5157214@news.ipswich.gil.com.au> <u9k9jsuawy.fsf@yorick.cygnus.com> <33a87d7b.3835586@news.ipswich.gil.com.au> <u9zpsmuktq.fsf@yorick.cygnus.com>
X-Original-Date: Sat, 21 Jun 1997 04:41:40 GMT
Organization: Global Info-Links News Server
X-Auth: PGPMoose V1.1 PGP comp.std.c++ iQBVAwUBM67f40y4NqrwXLNJAQFflQIAvY/Ta6rfsYQuXymqJcypTHQ95JzW0Xaq X0K4J4UXhOr/f20gVu/m80DAp9WoqyPNKQn9HwuMvIVkG00E6KrStQ== =p8ay
Newsgroups: comp.std.c++
Originator: austern@isolde.mti.sgi.com


On 20 Jun 1997 10:19:52 PDT, Jason Merrill <jason@cygnus.com> wrote:
>...
>15Whenever a class object is copied and the original object and the copy
>  have the same type, and the lifetime of the original object ends
>  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.
>
>* For the purposes of this rule, implicit destructor calls are not
>  considered in the lifetime of an object.

On further consideration it has occurred to me that the elision of a
temporary created as a result of a conversion operator on a function
call would not be allowed by this wording of 12.8/15, as after the
temporary is copied there is an entire function call before the temp
is destructed at the end of the full-expression.

In every case except for the NRVO, the copy being elided is a copy of
a newly-constructed class temporary (rvalue). So perhaps rather than
attempting to have one simple rule that includes the NRVO, it may be
better to treat it as a special case i.e.

"
12.8/15
In a copy-initialisation (8.5/12), if the source type is identical to
the destination type and is a class rvalue, or in a function return
(6.63) is an lvalue of automatic storage duration, then the copy can
be elided and the source object constructed directly in the
destination's storage.
(Note: *this in a member function of a class temporary is an lvalue
expression and hence this paragraph does not apply when copying it.)"

I put the note about *this to make it clear that copies of *this in a
member function are (correctly) not elided even if "this" is an
rvalue.

Any comments on this wording?

,Brian Parker (bparker@gil.com.au)
---
[ 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 
]



