[llvm] 3a8d771 - [llvm][NFC] Simplify implementation of `isa` (#161403)

via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 30 11:30:12 PDT 2025


Author: Victor Chernyakin
Date: 2025-09-30T11:30:07-07:00
New Revision: 3a8d771612c6d9d95c2e020aa37dd3674279432f

URL: https://github.com/llvm/llvm-project/commit/3a8d771612c6d9d95c2e020aa37dd3674279432f
DIFF: https://github.com/llvm/llvm-project/commit/3a8d771612c6d9d95c2e020aa37dd3674279432f.diff

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

Using a fold instead of template recursion.

Added: 
    

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

Removed: 
    


################################################################################
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