[PATCH] D127231: Restore isa<Ty>(X) asserts inside cast<Ty>(X)

Philip Reames via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 8 07:32:55 PDT 2022


This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGf0d2a55d3aa6: Restore isa<Ty>(X) asserts inside cast<Ty>(X) (authored by reames).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D127231/new/

https://reviews.llvm.org/D127231

Files:
  llvm/include/llvm/Support/Casting.h


Index: llvm/include/llvm/Support/Casting.h
===================================================================
--- llvm/include/llvm/Support/Casting.h
+++ llvm/include/llvm/Support/Casting.h
@@ -563,21 +563,25 @@
 
 template <typename To, typename From>
 LLVM_NODISCARD inline decltype(auto) cast(const From &Val) {
+  assert(isa<To>(Val) && "cast<Ty>() argument of incompatible type!");
   return CastInfo<To, const From>::doCast(Val);
 }
 
 template <typename To, typename From>
 LLVM_NODISCARD inline decltype(auto) cast(From &Val) {
+  assert(isa<To>(Val) && "cast<Ty>() argument of incompatible type!");
   return CastInfo<To, From>::doCast(Val);
 }
 
 template <typename To, typename From>
 LLVM_NODISCARD inline decltype(auto) cast(From *Val) {
+  assert(isa<To>(Val) && "cast<Ty>() argument of incompatible type!");
   return CastInfo<To, From *>::doCast(Val);
 }
 
 template <typename To, typename From>
 LLVM_NODISCARD inline decltype(auto) cast(std::unique_ptr<From> &&Val) {
+  assert(isa<To>(Val) && "cast<Ty>() argument of incompatible type!");
   return CastInfo<To, std::unique_ptr<From>>::doCast(std::move(Val));
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D127231.435155.patch
Type: text/x-patch
Size: 1135 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220608/96402018/attachment.bin>


More information about the llvm-commits mailing list