[Bug c++/51571] New: No named return value optimization while adding a dummy scope
prasoonsaurav.nit at gmail dot com
gcc-bugzilla@gcc.gnu.org
Thu Dec 15 16:44:00 GMT 2011
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51571
Bug #: 51571
Summary: No named return value optimization while adding a
dummy scope
Classification: Unclassified
Product: gcc
Version: 4.6.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: prasoonsaurav.nit@gmail.com
Simple code snippet
#include <iostream>
int global;
struct A
{
A(){}
A(const A&x){
++global;
}
~A(){}
};
A foo()
{
A a;
return a;
}
int main()
{
A x = foo();
std::cout << global;
}
Output : 0
When the definition of foo is changed to
A foo()
{
{
A a;
return a;
}
}
I get 1 as the output i.e copy c-tor gets called once.
Compiler is not optimizing the call to the copy c-tor in this case.
More information about the Gcc-bugs
mailing list