Topic: return value optimization and throw


Author: tony@online.tmx.com.au (Tony Cook)
Date: 1996/09/23
Raw View
Trevor Yann (ty@kodak.com.au) wrote:
: Does a variation of the return value optimization apply to thrown objects?

: e.g.
:  throw MyExceptionClass();

: Is it necessary that the MyExceptionClass constructor be called,
: then the copy constructor?

The compiler is permitted to optimize away the copy constructor
call.  The copy constructor must be accessible though.

: Wouldn't it be possible for the compiler to determine that the
: object was going to be thrown, and construct it accordingly?

Yes.


--
        Tony Cook - tony@online.tmx.com.au
                    100237.3425@compuserve.com


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





Author: Trevor Yann <ty@kodak.com.au>
Date: 1996/09/18
Raw View
Does a variation of the return value optimization apply to thrown objects?

e.g.
 throw MyExceptionClass();

Is it necessary that the MyExceptionClass constructor be called, then the copy
constructor?

Wouldn't it be possible for the compiler to determine that the object was going
to be thrown, and construct it accordingly?



Trevor Yann
---
[ 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
]