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

Erich Keane via cfe-commits cfe-commits at lists.llvm.org
Wed Aug 6 08:19:55 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) ||
----------------
erichkeane wrote:

```suggestion
  assert(isa<const TemplateSpecializationType *, const SubstBuiltinTemplatePackType *>(UPP.first));
```

Pretty sure this works?

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


More information about the cfe-commits mailing list