[PATCH] D147991: [LLVM][Casting.h] Fix dyn_cast for std::unique_ptr.
Aman LaChapelle via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 11 11:37:08 PDT 2023
bzcheeseman accepted this revision.
bzcheeseman added inline comments.
================
Comment at: llvm/include/llvm/Support/Casting.h:358
return castFailed();
- return doCast(f);
+ return doCast(std::forward<std::unique_ptr<From> &&>(f));
}
----------------
I think you want `std::forward<std::unique_ptr<From>>(f)`? - see here:
https://en.cppreference.com/w/cpp/utility/forward
```
For example, if used in a wrapper such as the following, the template behaves as described below:
template<class T>
void wrapper(T&& arg)
{
// arg is always lvalue
foo(std::forward<T>(arg)); // Forward as lvalue or as rvalue, depending on T
}
If a call to wrapper() passes an rvalue std::string, then T is deduced to std::string (not std::string&, const std::string&, or std::string&&), and std::forward ensures that an rvalue reference is passed to foo.
If a call to wrapper() passes a const lvalue std::string, then T is deduced to const std::string&, and std::forward ensures that a const lvalue reference is passed to foo.
If a call to wrapper() passes a non-const lvalue std::string, then T is deduced to std::string&, and std::forward ensures that a non-const lvalue reference is passed to foo.
```
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D147991/new/
https://reviews.llvm.org/D147991
More information about the llvm-commits
mailing list