decltype(auto) function return type does not deduce && types
By : Mihir Sabnis
Date : October 25 2020, 07:10 AM
seems to work fine This seems to be a bug in GCC. Since decltype(ret) is int&&, foo1 should have return type int&&. However, this immediately renders foo1 ill-formed, since a function that returns int&& cannot have its return value initialized from ret, which is an lvalue (you would need std::move to make it work properly). Note that Clang gets this right (see link in comments to the question).