|
Boost : |
From: Marc Duflot (m.duflot_at_[hidden])
Date: 2002-10-24 07:47:04
Daniel Frey wrote:
> #include <iostream>
> using namespace std;
>
> struct X
> {
> X() { cout << "X"; }
> X( const X& ) { cout << "C"; }
> };
>
> X f()
> {
> return X();
> }
>
> X g()
> {
> X x;
> return x;
> }
>
> #define TEST( code ) \
> cout << #code << "\t: "; code; cout << endl
>
> int main()
> {
> TEST( f() );
> TEST( g() );
> TEST( X( f() ) );
> TEST( X( g() ) );
> TEST( X x1( f() ); );
> TEST( X x2( g() ); );
> TEST( X x3 = f(); );
> TEST( X x4 = g(); );
> }
g++ 2.95.2
f() : X
g() : XC
X( f() ) :
X( g() ) :
X x1( f() ); : X
X x2( g() ); : XC
X x3 = f(); : X
X x4 = g(); : XC
g++ 3.0.4
f() : X
g() : XC
X( f() ) :
X( g() ) :
X x1( f() ); : XC
X x2( g() ); : XCC
X x3 = f(); : X
X x4 = g(); : XC
g++ 3.1 and 3.2
f() : X
g() : X
X( f() ) :
X( g() ) :
X x1( f() ); : X
X x2( g() ); : X
X x3 = f(); : X
X x4 = g(); : X
Intel C++ 6.0
f() : X
g() : X
X( f() ) :
X( g() ) :
X x1( f() ); : XC
X x2( g() ); : XC
X x3 = f(); : X
X x4 = g(); : X
SGI MipsPro Compiler
f() : X
g() : X
X( f() ) :
X( g() ) :
X x1( f() ); : XC
X x2( g() ); : XC
X x3 = f(); : X
X x4 = g(); : X
Visual C++ 6
f() : X
g() : XC
X( f() ) :
X( g() ) :
X x1( f() ); : X
X x2( g() ); : XC
X x3 = f(); : X
X x4 = g(); : XC
Summary:
* g++ 3.0.4: bad
* g++ 2.95.2 and Visual C++ 6: average: RVO but not NRVO
* Intel C++ 6.0 and SGI MipsPro Compiler (both based on EDG): good: RVO and
NRVO except with X x( f() );
* g++ 3.2: best
Every compiler outputs nothing for X( f() ) and X( g() ).
-- Marc Duflot http://vesta.ltas.ulg.ac.be/~duflot/
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk