https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67795
--- Comment #8 from frankhb1989 at gmail dot com --- (In reply to Markus Trippelsdorf from comment #4) > Return by value if you want to avoid undefined behavior. No. This is not the point. For something like 'std::move' or 'std::forward', can you suggest such change? The code of the case is reduced from a function template which return 'S&&', where 'S' is a template type parameter (and 'S&&' is also in function parameter list for perfect forwarding). Simply returning object type is not acceptable in the original case because: 1. Even move construction for 'S' is not guaranteed to be zero overhead. 2.It needs one more static_cast/std::move in many places of the the client code which makes it bloat A LOT.