[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:38 PDT 2025


================
@@ -3331,6 +3343,65 @@ checkBuiltinTemplateIdType(Sema &SemaRef, BuiltinTemplateDecl *BTD,
     QualType HasNoTypeMember = Converted[2].getAsType();
     return HasNoTypeMember;
   }
+  case BTK__builtin_dedup_pack: {
+    assert(Converted.size() == 1 && "__builtin_dedup_pack should be given "
+                                    "a parameter pack");
+    TemplateArgument Ts = Converted[0];
+    // Delay the computation until we can compute the final result. We choose
+    // not to remove the duplicates upfront before substitution to keep the code
+    // simple.
+    if (Ts.isDependent())
+      return QualType();
+    assert(Ts.getKind() == clang::TemplateArgument::Pack);
+    llvm::SmallVector<TemplateArgument> OutArgs;
+    llvm::SmallDenseSet<QualType> Seen;
+    // Synthesize a new template argument list, removing duplicates.
+    for (auto T : Ts.getPackAsArray()) {
----------------
ilya-biryukov wrote:

It still does not work, the vector and set will still need to have the same type to use it conveniently.

It would be possible to achieve this with a `SetVector` and custom comparator, but the amount of boilerplate there will be larger than having two collections and the resulting code looks much harder to read.

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


More information about the cfe-commits mailing list