[clang] [clang-tools-extra] [Clang] Add a builtin that deduplicate types into a pack (PR #106730)

Ilya Biryukov via cfe-commits cfe-commits at lists.llvm.org
Mon Aug 11 10:47:39 PDT 2025


================
@@ -71,12 +73,17 @@ inline std::pair<unsigned, unsigned> getDepthAndIndex(const NamedDecl *ND) {
 }
 
 /// Retrieve the depth and index of an unexpanded parameter pack.
-inline std::pair<unsigned, unsigned>
+/// Returns nullopt when the unexpanded packs do not correspond to template
+/// parameters, e.g. __builtin_dedup_types.
+inline std::optional<std::pair<unsigned, unsigned>>
 getDepthAndIndex(UnexpandedParameterPack UPP) {
   if (const auto *TTP = dyn_cast<const TemplateTypeParmType *>(UPP.first))
     return std::make_pair(TTP->getDepth(), TTP->getIndex());
-
-  return getDepthAndIndex(cast<NamedDecl *>(UPP.first));
+  if (isa<NamedDecl *>(UPP.first))
+    return getDepthAndIndex(cast<NamedDecl *>(UPP.first));
+  assert(isa<const TemplateSpecializationType *>(UPP.first) ||
----------------
ilya-biryukov wrote:

It does, with a caveat that we need to add an extra set of parenthesis so that the comma does not get interpreted as a macro argument delimiter.

Thanks!

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


More information about the cfe-commits mailing list