This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/37487] New: invalid return by value optimization


For return by value optimization, instead of calling the copy constructor or
the assignment operator, gcc decides to optimize and push the address of the
lhs of the expression into the rhs.

Foo createFoo() { Foo f2; return f2; }
int main(){
  Foo f1 = createFoo();
  return 0;
}

OPTIMIZED TO
void createFoo( Foo& f2 ) {...} 
int main() {
  Foo f1;
  createFoo(f1);
  return 0;
}

This is a problem when you want to explicitly define the copy constructor or
assignment operator to do something other than deep copying.


-- 
           Summary: invalid return by value optimization
           Product: gcc
           Version: 3.4.6
            Status: UNCONFIRMED
          Severity: blocker
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: khoaduynguyen at gmail dot com


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37487


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]