[Bug c++/37487] New: invalid return by value optimization
khoaduynguyen at gmail dot com
gcc-bugzilla@gcc.gnu.org
Thu Sep 11 21:00:00 GMT 2008
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
More information about the Gcc-bugs
mailing list