From -9088805825489566878
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/20
Message-ID: <33a8768c.2060634@news.ipswich.gil.com.au>#1/1
X-Deja-AN: 251292084
References: <33a345bf.7425526@news.ipswich.gil.com.au> <33a4e2d5.24720499@news.ipswich.gil.com.au> <33A54D26.F46@acm.org> <33a5f2fc.3455132@news.ipswich.gil.com.au> <5o6rng$5ia@tools.bbnplanet.com>
X-Original-Date: Thu, 19 Jun 1997 03:23:08 GMT
Organization: Global Info-Links News Server
X-Auth: PGPMoose V1.1 PGP comp.std.c++ iQBFAgUBM6o/meEDnX0m9pzZAQEMsAGAkBLZrt/SlfgFVVBKizRCfXsDcbBRgQBv i+ovn+ujITL6OakpAj04iBUw42IPagQA =pBnL
Newsgroups: comp.std.c++
Originator: fjh@mundook.cs.mu.OZ.AU


On 18 Jun 97 02:13:20 GMT, Barry Margolin <barmar@bbnplanet.com>
wrote:

>In article <33a5f2fc.3455132@news.ipswich.gil.com.au>,
>Brian Parker <bparker@gil.com.au> wrote:
>>As far as I can see, 12.8/15 could only be unambiguously safely
>>applied by a compiler for a class with bitwise copy semantics, i.e.
>>either the class and all its members and base classes have implicitly
>>defined copy constructors, or any user-provided explicit copy
>>constructors must involve only simple assignment of members. In these
>>cases, though, the copy could already be elided by the "as if" rule.
>
>I suspect this is the optimization that this section is trying to allow.
>However, the as-if rule is not sufficient to permit it, because the as-if
>rule is violated if the class or any of its members or bases have side
>effects in their destructors (as in the destructor_count++ example that
>someone posted).

That's true- I forgot about user-provided destructors. My statement
above only applies if all destructors are also implicit.
 
>
>I think that NRVO should be reworded to specify that if the copy
>constructor has bitwise copy semantics, you can't depend on destructors
>being run during an assignment.

That may be a useful approach. If the copy constructor has bit-wise
semantics and the destructor is empty then the optimisations of
12.8/15 could already be done by the "as if" rule, but your proposal
would also allow them where there is a non-empty destructor.
I agree that that would be quite safe- the only question is whether
the additional optimisations allowed by this would be useful in
practice.

This would certainly solve the problems with 12.8/15, though.

Anyone else have any comments on this?

,Brian Parker (bparker@gil.com.au)
---
[ 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         ]
[ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
[ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]



