public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/51571] New: No named return value optimization while adding a dummy scope
@ 2011-12-15 16:44 prasoonsaurav.nit at gmail dot com
  2011-12-15 18:26 ` [Bug c++/51571] " prasoonsaurav.nit at gmail dot com
                   ` (13 more replies)
  0 siblings, 14 replies; 15+ messages in thread
From: prasoonsaurav.nit at gmail dot com @ 2011-12-15 16:44 UTC (permalink / raw)
  To: gcc-bugs

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.


^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2023-12-19 19:50 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-12-15 16:44 [Bug c++/51571] New: No named return value optimization while adding a dummy scope prasoonsaurav.nit at gmail dot com
2011-12-15 18:26 ` [Bug c++/51571] " prasoonsaurav.nit at gmail dot com
2011-12-15 22:08 ` pinskia at gcc dot gnu.org
2011-12-18 11:03 ` paolo.carlini at oracle dot com
2013-06-02  7:36 ` guillaume.melquiond at inria dot fr
2015-02-04 22:40 ` marc at kdab dot com
2020-07-05  9:44 ` glisse at gcc dot gnu.org
2020-10-26 16:15 ` mpolacek at gcc dot gnu.org
2020-10-26 16:16 ` mpolacek at gcc dot gnu.org
2023-06-06 16:12 ` jason at gcc dot gnu.org
2023-06-07  1:33 ` cvs-commit at gcc dot gnu.org
2023-06-07  1:35 ` jason at gcc dot gnu.org
2023-06-07 20:41 ` jason at gcc dot gnu.org
2023-10-17 10:29 ` rguenth at gcc dot gnu.org
2023-12-19 19:50 ` jason at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).