From -6845388283303152565
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,f5d433881cc29cff
X-Google-Attributes: gidf78e5,public
From: Mike Ferrel <mferrel@sr.hp.com>
Subject: Re: Named return value optimisation- reprise.
Date: 1997/06/23
Message-ID: <33AACCA6.6C30@sr.hp.com>#1/1
X-Deja-AN: 252083341
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> <33a9da21.2670962@news.ipswich.gil.com.au>
X-Original-Date: Fri, 20 Jun 1997 11:32:06 -0700
Organization: Hewlett Packard Sonoma County
X-Auth: PGPMoose V1.1 PGP comp.std.c++ iQBVAwUBM67fw0y4NqrwXLNJAQELFgIAny5X6GcVsU3JSupiqMNGWTTbhiyQ8oFi ZT+4dFyQuL+LQSath5k06WphcIhvS6ceQVzk7ZSWePxLN+910VXDzg== =ofgz
Newsgroups: comp.std.c++
Originator: austern@isolde.mti.sgi.com


Brian Parker wrote:
> 
> I wonder if a better rewording of 12.8/15 would be to simply add a
> sentence preventing its use on pass-by-value.
> 
> i.e. change 12.8/15 to -
> 
> "Whenever a class object [intro.object] is copied via a *copy
> constructor* and the original object and the copy have the same type,
> *except on pass-by-value (5.2.2 Function call)* if the implementation
> can prove ... (rest of wording the same)."
> 
> And remove the current examples, replacing them with a NRVO example.
> 
> This would still allow copies to be elided on NRVO, RVO and
> initialisation of variables.
> 
I have been following this thread with some bemusement, and can't
understand how a compiler could possibly replace a call-by-value with a
call by reference. The function body would have to contain entirely 
different code.  For this to be possible, the compiler would have to
generate different function bodies containing code to accept value
parameters
as value parameters, and as reference parameters.  For functions with
more
than one value parameter, the exponential increase in numbers of
distinct function bodies would cause impossible code bloat.

The only way I see the compiler could possibly reasonably alter call 
semantics is if the function were declared static, and its definition
occured after all calls, and the compiler had determined that the
optimisation could be used in all calls.  It seems like that's an awful
lot of compiler housekeeping for an exceedingly rare occurence.  I can't
imagine any implementer going to the effort.

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



