hope this fix your issue Yes it's still wrong. The compiler cannot detect all cases where you're doing dangerous (or illegal) things. It warns when it does find them, but it can't identify all cases (and doesn't have to).
avoid returning local references (reference to local variable returned - warning)
hope this fix your issue The reason it's illegal to return the address to a local variable is once the function returns, the local variable ceases to exist, thus you're returning an address which is known to be no longer valid. (The object may still live there but its destructor will have already been called, and the memory it occupied will be used for something else at some point -- perhaps with the very next subroutine call.) The reason it's ok to return the address returned by new is that address is not pointing to an object that lives in a temporary location (your program stack is where locals are normally placed); rather it comes from heap memory which will persist until you dispose of it. This object doesn't rely on the scope of code it was allocated in since it's not local to that scope.
Does returning a local object require move semantics?
hope this fix your issue You are simply meeting the intended behaviour of overload resolution: Foo() is an rvalue, so overload resolution finds the constructor Foo(Foo&&) as the best match. Since that overload is deleted, your program is ill-formed. Moreover, there's a special rule that says Foo a; return a; will also perform overload resolution as if a was an rvalue first. (The rule applies essentially whenever the the return statement is eligible for copy elision.) This is all working as intended. It was you who deleted the overload, so you requested expressly that such constructions be forbidden.
Why does gcc throw a warning when returning a pointer to a local variable and not when returning a local variable?