diff --git a/llvm/include/llvm/Support/Casting.h b/llvm/include/llvm/Support/Casting.h index 0c71882a77b1..80f09db4f7ac 100644 --- a/llvm/include/llvm/Support/Casting.h +++ b/llvm/include/llvm/Support/Casting.h @@ -55,8 +55,8 @@ struct isa_impl { /// \brief Always allow upcasts, and perform no dynamic check for them. template struct isa_impl::value + typename enable_if< + llvm::is_base_of >::type > { static inline bool doit(const From &) { return true; } @@ -204,12 +204,35 @@ template struct cast_convert_val { // cast(myVal)->getParent() // template -inline typename cast_retty::ret_type cast(const Y &Val) { +inline typename enable_if_c< + !is_same::SimpleType>::value, + typename cast_retty::ret_type +>::type cast(const Y &Val) { assert(isa(Val) && "cast() argument of incompatible type!"); return cast_convert_val::SimpleType>::doit(Val); } +template +inline typename enable_if< + is_same::SimpleType>, + typename cast_retty::ret_type +>::type cast(Y &Val) { + assert(isa(Val) && "cast() argument of incompatible type!"); + return cast_convert_val::SimpleType>::doit(Val); +} + +template +inline typename enable_if< + is_same::SimpleType>, + typename cast_retty::ret_type +>::type cast(Y *Val) { + assert(isa(Val) && "cast() argument of incompatible type!"); + return cast_convert_val::SimpleType>::doit(Val); +} + // cast_or_null - Functionally identical to cast, except that a null value is // accepted. // @@ -230,8 +253,27 @@ inline typename cast_retty::ret_type cast_or_null(Y *Val) { // template -inline typename cast_retty::ret_type dyn_cast(const Y &Val) { - return isa(Val) ? cast(Val) : 0; +inline typename enable_if_c< + !is_same::SimpleType>::value, + typename cast_retty::ret_type +>::type dyn_cast(const Y &Val) { + return isa(Val) ? cast(Val) : 0; +} + +template +inline typename enable_if< + is_same::SimpleType>, + typename cast_retty::ret_type +>::type dyn_cast(Y &Val) { + return isa(Val) ? cast(Val) : 0; +} + +template +inline typename enable_if< + is_same::SimpleType>, + typename cast_retty::ret_type +>::type dyn_cast(Y *Val) { + return isa(Val) ? cast(Val) : 0; } // dyn_cast_or_null - Functionally identical to dyn_cast, except that a null