[llvm] ab7a683 - [TypeSwitch] Use perfect forwarding in the cast functions
River Riddle via llvm-commits
llvm-commits at lists.llvm.org
Fri Dec 2 00:48:59 PST 2022
Author: River Riddle
Date: 2022-12-02T00:48:35-08:00
New Revision: ab7a683546c062a5f05c292fad9a4b71567fa409
URL: https://github.com/llvm/llvm-project/commit/ab7a683546c062a5f05c292fad9a4b71567fa409
DIFF: https://github.com/llvm/llvm-project/commit/ab7a683546c062a5f05c292fad9a4b71567fa409.diff
LOG: [TypeSwitch] Use perfect forwarding in the cast functions
This allows for properly supporting TypeSwitch on reference
types which do not support copying/do not want copying.
Added:
Modified:
llvm/include/llvm/ADT/TypeSwitch.h
Removed:
################################################################################
diff --git a/llvm/include/llvm/ADT/TypeSwitch.h b/llvm/include/llvm/ADT/TypeSwitch.h
index 044b2432b8243..523ff544a02b5 100644
--- a/llvm/include/llvm/ADT/TypeSwitch.h
+++ b/llvm/include/llvm/ADT/TypeSwitch.h
@@ -71,8 +71,8 @@ template <typename DerivedT, typename T> class TypeSwitchBase {
/// Attempt to dyn_cast the given `value` to `CastT`. This overload is
/// selected if `value` already has a suitable dyn_cast method.
template <typename CastT, typename ValueT>
- static auto castValue(
- ValueT value,
+ static decltype(auto) castValue(
+ ValueT &&value,
std::enable_if_t<is_detected<has_dyn_cast_t, ValueT, CastT>::value> * =
nullptr) {
return value.template dyn_cast<CastT>();
@@ -81,8 +81,8 @@ template <typename DerivedT, typename T> class TypeSwitchBase {
/// Attempt to dyn_cast the given `value` to `CastT`. This overload is
/// selected if llvm::dyn_cast should be used.
template <typename CastT, typename ValueT>
- static auto castValue(
- ValueT value,
+ static decltype(auto) castValue(
+ ValueT &&value,
std::enable_if_t<!is_detected<has_dyn_cast_t, ValueT, CastT>::value> * =
nullptr) {
return dyn_cast<CastT>(value);
More information about the llvm-commits
mailing list