diff --git a/mlir/include/mlir/IR/Attributes.h b/mlir/include/mlir/IR/Attributes.h --- a/mlir/include/mlir/IR/Attributes.h +++ b/mlir/include/mlir/IR/Attributes.h @@ -60,9 +60,6 @@ template U cast() const; - // Support dyn_cast'ing Attribute to itself. - static bool classof(Attribute) { return true; } - /// Return a unique identifier for the concrete attribute type. This is used /// to support dynamic type casting. TypeID getTypeID() { return impl->getAbstractAttribute().getTypeID(); } @@ -394,8 +391,12 @@ static inline bool isPossible(mlir::Attribute ty) { /// Return a constant true instead of a dynamic true when casting to self or /// up the hierarchy. - return std::is_same_v> || - std::is_base_of_v || To::classof(ty); + if constexpr (std::is_same_v> || + std::is_base_of_v) { + return true; + } else { + return To::classof(ty); + } } static inline To doCast(mlir::Attribute attr) { return To(attr.getImpl()); } }; diff --git a/mlir/include/mlir/IR/Types.h b/mlir/include/mlir/IR/Types.h --- a/mlir/include/mlir/IR/Types.h +++ b/mlir/include/mlir/IR/Types.h @@ -107,9 +107,6 @@ template U cast() const; - // Support type casting Type to itself. - static bool classof(Type) { return true; } - /// Return a unique identifier for the concrete type. This is used to support /// dynamic type casting. TypeID getTypeID() { return impl->getAbstractType().getTypeID(); } @@ -387,8 +384,12 @@ static inline bool isPossible(mlir::Type ty) { /// Return a constant true instead of a dynamic true when casting to self or /// up the hierarchy. - return std::is_same_v> || - std::is_base_of_v || To::classof(ty); + if constexpr (std::is_same_v> || + std::is_base_of_v) { + return true; + } else { + return To::classof(ty); + }; } static inline To doCast(mlir::Type ty) { return To(ty.getImpl()); } };