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: unassig...@gcc.gnu.org ReportedBy: prasoonsaurav....@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.