DR1579 says that when returning a id-expression from a function, we should attempt to return said expression by move first, then fallback to copy.
This patch does this by generalizing PerformMoveOrCopyElision, which previously did this when returning a id-expression that was a parameter.
This patch allows the following code to compile, for example:
struct Base {};
struct Derived : public Base {};
std::unique_ptr<Base> f() {
std::unique_ptr<Derived> d;
return d;
}The DR in question: http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#1579
Pointed out by PR27785.
Thanks!