Skip to content

Conversation

@kazutakahirata
Copy link
Contributor

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

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

llvmbot commented Sep 18, 2025

@llvm/pr-subscribers-llvm-adt

Author: Kazu Hirata (kazutakahirata)

Changes

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

Copy link
Member

@JoeLoser JoeLoser left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice cleanup 👍

@kazutakahirata kazutakahirata merged commit 97e544f into llvm:main Sep 18, 2025
11 checks passed
@kazutakahirata kazutakahirata deleted the cleanup_20250917_ADT_PointerSumType_Checker branch September 18, 2025 15:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants