[libc++] Fix std::forward for r-value references
The explicit cast is necessary even though the value for
t is passed in as an r-value, because it becomes an l-value as soon as it is assigned to the variable.
Without the change in libc++ the updated test fails with:
In file included from tests/stl/stl_utility.cpp:1: share/libc++/utility:58:12: error: rvalue reference to type 'int' cannot bind to lvalue of type 'typename remove_reference<int>::type' (aka 'int') return t; ^ tests/stl/stl_utility.cpp:18:20: note: in instantiation of function template specialization 'std::forward<int>' requested here int && xr = std::forward<int>(x + 1); ^ code generation aborted due to one compilation error
The change follows the implementation in LLVM libcxx: https://github.com/llvm/llvm-project/blob/abfa950d86da1737/libcxx/include/__utility/forward.h#L35