Re: why visual studio does not optimize constructor in this case



 DEVELOP > c-Plus-Plus > Re: why visual studio does not optimize constructor in this case

LINK TO THIS PAGE  


rating :  0   |  0


  Page 1 of 1

1

 
Topic: DEVELOP > c-Plus-Plus
User: "Tristan Wibberley"
Date: 27 Dec 2007 04:06:50 PM
Object: Re: why visual studio does not optimize constructor in this case
On Thu, 2007-12-27 at 16:23 +0100, Tadeusz B. Kopec wrote:


Output is,

I am in constructor
I am in constructor
I am in copy constructor

My expected output is,

I am in constructor
I am in constructor


The standard says that compiler is allowed to elide copy in return value
but doesn't require it. Whether a specific compiler does this
optimisation or not is implementation defined so off topic here.

I understood that the copy constructor must not be elided if it would
result in a different program. IE, any statistics gathering, reference
counting or custom allocators being used prevents elision (is that a
word?) except where the compiler can (and will) prove that the elided
version would give the same result in all cases.
--
Tristan Wibberley
Any opinion expressed is mine (or else I'm playing devils advocate for
the sake of a good argument). My employer had nothing to do with this
communication.
.

User: "=?UTF-8?B?RXJpayBXaWtzdHLDtm0=?="

Title: Re: why visual studio does not optimize constructor in this case 27 Dec 2007 04:53:16 PM
On 2007-12-27 23:06, Tristan Wibberley wrote:

On Thu, 2007-12-27 at 16:23 +0100, Tadeusz B. Kopec wrote:


Output is,

I am in constructor
I am in constructor
I am in copy constructor

My expected output is,

I am in constructor
I am in constructor


The standard says that compiler is allowed to elide copy in return value
but doesn't require it. Whether a specific compiler does this
optimisation or not is implementation defined so off topic here.


I understood that the copy constructor must not be elided if it would
result in a different program. IE, any statistics gathering, reference
counting or custom allocators being used prevents elision (is that a
word?) except where the compiler can (and will) prove that the elided
version would give the same result in all cases.

Actually no, the copy-constructor may always be elided, even if that
changes the effects of the program. That is why it is possible to
demonstrate the effects using print-outs in the copy constructor.
Because of this a copy-constructor should be designed to only copy an
object and nothing more, and you should never design your programs to
rely on the copy-constructor running.
--
Erik Wikström
.


  Page 1 of 1

1

 


Related Articles
 

NEWER

pg.1232     pg.940     pg.716     pg.544     pg.412     pg.311     pg.234     pg.175     pg.130     pg.96     pg.70     pg.50     pg.35     pg.24     pg.16     pg.10     pg.6     pg.3     pg.1

OLDER