[llvm] [ADT] Use C++17 fold expression in PointerSumType (NFC) (PR #159560)

via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 18 04:55:58 PDT 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-adt

Author: Kazu Hirata (kazutakahirata)

<details>
<summary>Changes</summary>

This patch simplifes the recursive Checker template with a C++17 fold
expression and "inlines" it right into the `static_assert`.


---
Full diff: https://github.com/llvm/llvm-project/pull/159560.diff


1 Files Affected:

- (modified) llvm/include/llvm/ADT/PointerSumType.h (+3-13) 


``````````diff
diff --git a/llvm/include/llvm/ADT/PointerSumType.h b/llvm/include/llvm/ADT/PointerSumType.h
index 132eab58b112a..c4971bf3af87a 100644
--- a/llvm/include/llvm/ADT/PointerSumType.h
+++ b/llvm/include/llvm/ADT/PointerSumType.h
@@ -239,19 +239,9 @@ struct PointerSumTypeHelper : MemberTs... {
     TagMask = ~PointerMask
   };
 
-  // Finally we need a recursive template to do static checks of each
-  // member.
-  template <typename MemberT, typename... InnerMemberTs>
-  struct Checker : Checker<InnerMemberTs...> {
-    static_assert(MemberT::Tag < (1 << NumTagBits),
-                  "This discriminant value requires too many bits!");
-  };
-  template <typename MemberT> struct Checker<MemberT> : std::true_type {
-    static_assert(MemberT::Tag < (1 << NumTagBits),
-                  "This discriminant value requires too many bits!");
-  };
-  static_assert(Checker<MemberTs...>::value,
-                "Each member must pass the checker.");
+  // Finally, statically check each member.
+  static_assert(((MemberTs::Tag < (1 << NumTagBits)) && ...),
+                "A discriminant value requires too many bits!");
 };
 
 } // end namespace detail

``````````

</details>


https://github.com/llvm/llvm-project/pull/159560


More information about the llvm-commits mailing list