NRVO


S

Staffan Langin

Hello,

I've earlier been told by MS that the upcoming C++ compiler (VS2005) should
utilize NRVO. When compiling the program below with VS2005 Aug CTP release,
it doesn't seem as it performs NRVO. What's the status of VS2005 and NRVO?

Staffan Langin


#include "stdafx.h"

#include <iostream>

struct T
{
T() {std::cout<<"D";}
T(int) {std::cout<<"D";}
T(T const&) {std::cout<<"C";}
T& operator+=(T const&) {return *this;}
};


T
f1()
{
return T();
}


T
f2()
{
T t;
return t;
}


T
f3()
{
T t;
t=T();
return t;
}


T
a1(T const& lhs,T const& rhs)
{
T t(lhs);
t+=rhs;
return t;
}


T
a2(T const& lhs,T const& rhs)
{
T t=lhs;
t+=rhs;
return t;
}


int _tmain(int argc, _TCHAR* argv[])
{
std::cout<<"min D max D = ";
T t1;
std::cout<<std::endl;
std::cout<<"min D max DC = ";
T t2(T(1));
std::cout<<std::endl;
std::cout<<"min D max DC = ";
T t3=T();
std::cout<<std::endl;
std::cout<<"min D max DCC = ";
T t4(f1());
std::cout<<std::endl;
std::cout<<"min D max DCC = ";
T t5=f1();
std::cout<<std::endl;
std::cout<<"min D max DCC = ";
T t6(f2());
std::cout<<std::endl;
std::cout<<"min D max DCC = ";
T t7=f2();
std::cout<<std::endl;
std::cout<<"min DD max DDCC = ";
T t8(f3());
std::cout<<std::endl;
std::cout<<"min DD max DDCC = ";
T t9=f3();
std::cout<<std::endl;
std::cout<<"min C max CCC = ";
T u1(a1(t1,t2));
std::cout<<std::endl;
std::cout<<"min C max CCC = ";
T u2=a1(t1,t2);
std::cout<<std::endl;
std::cout<<"min C max CCC = ";
T u3(a2(t1,t2));
std::cout<<std::endl;
std::cout<<"min C max CCC = ";
T u4=a2(t1,t2);
std::cout<<std::endl;
return 0;
}


Output:

min D max D = D
min D max DC = D
min D max DC = D
min D max DCC = D
min D max DCC = D
min D max DCC = DC
min D max DCC = DC
min DD max DDCC = DDC
min DD max DDCC = DDC
min C max CCC = CC
min C max CCC = CC
min C max CCC = CC
min C max CCC = CC
 
Ad

Advertisements

S

Staffan Langin

http://msdn.microsoft.com/chats/transcripts/vstudio/vstudio_022703.aspx
Here you can read:
Host: Jeff (Microsoft)
Q: I am surprised to hear that Everett does not implement RVO. Does it
implement NRVO (named-RVO) at all?

A: We do RVO, just not NRVO.

Rodrigo,

That transcript seems to refer to VS2003 (Everett) and not VS2005. If one
looks at the output from the program in my original post, VS2005 Aug CTP
release also seems to support RVO but not NRVO but I'd like someone from MS
to confirm that's the specification of the final version aswell.

Staffan
 
T

Tom Widmer [VC++ MVP]

Ad

Advertisements


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top