[Bug c++/58051] New: No named return value optimization when returned object is implicitly converted
scovich at gmail dot com
gcc-bugzilla@gcc.gnu.org
Fri Aug 2 04:33:00 GMT 2013
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58051
Bug ID: 58051
Summary: No named return value optimization when returned
object is implicitly converted
Product: gcc
Version: 4.8.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: scovich at gmail dot com
The following test case introduces an extra object copy, even though none
should be required:
// <<<--- bug.cpp --->>>
extern "C" void puts(char const *);
struct A {
A()=default;
A(A &&)=default;
A(A const &) { puts("copy"); }
~A() { puts("~A"); }
};
struct B {
A _a;
B(A a) : _a((A&&)(a)) { }
};
B go() {
A rval;
return rval;
}
int main () { go(); }
// <<<--- end bug.cpp --->>>
(when compiled with both `gcc-4.8.1 -std=gnu++11' and `gcc-4.6.3 -std=gnu++0x')
RVO works properly if go() returns A() or std::move(rval).
More information about the Gcc-bugs
mailing list