[llvm] [llvm][NFC] Simplify implementation of `isa` (PR #161403)

Victor Chernyakin via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 30 10:00:14 PDT 2025


https://github.com/localspook created https://github.com/llvm/llvm-project/pull/161403

Using a fold instead of template recursion.

>From 3a49ad025fa603d99f59b916f50e819fde7328cb Mon Sep 17 00:00:00 2001
From: Victor Chernyakin <chernyakin.victor.j at outlook.com>
Date: Tue, 30 Sep 2025 09:57:00 -0700
Subject: [PATCH] [llvm][NFC] Simplify implementation of `isa`

---
 llvm/include/llvm/Support/Casting.h | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)

diff --git a/llvm/include/llvm/Support/Casting.h b/llvm/include/llvm/Support/Casting.h
index 66fdcb44ea2c0..2a9a149327d83 100644
--- a/llvm/include/llvm/Support/Casting.h
+++ b/llvm/include/llvm/Support/Casting.h
@@ -544,14 +544,9 @@ struct CastInfo<To, std::optional<From>> : public OptionalValueCast<To, From> {
 ///
 ///  if (isa<Type>(myVal)) { ... }
 ///  if (isa<Type0, Type1, Type2>(myVal)) { ... }
-template <typename To, typename From>
-[[nodiscard]] inline bool isa(const From &Val) {
-  return CastInfo<To, const From>::isPossible(Val);
-}
-
-template <typename First, typename Second, typename... Rest, typename From>
+template <typename... To, typename From>
 [[nodiscard]] inline bool isa(const From &Val) {
-  return isa<First>(Val) || isa<Second, Rest...>(Val);
+  return (CastInfo<To, const From>::isPossible(Val) || ...);
 }
 
 /// cast<X> - Return the argument parameter cast to the specified type.  This



More information about the llvm-commits mailing list