This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/51571] New: No named return value optimization while adding a dummy scope
- From: "prasoonsaurav.nit at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Thu, 15 Dec 2011 16:39:05 +0000
- Subject: [Bug c++/51571] New: No named return value optimization while adding a dummy scope
- Auto-submitted: auto-generated
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.