[clang] [Sema]Substitue parameter packs when deduced from function parameter (PR #79371)

Gábor Spaits via cfe-commits cfe-commits at lists.llvm.org
Thu Jan 25 10:08:35 PST 2024


================
@@ -858,6 +859,30 @@ class PackDeductionScope {
       Info.PendingDeducedPacks[Pack.Index] = Pack.Outer;
   }
 
+  std::optional<unsigned> getSavedPackSize(unsigned Index,
+                                           TemplateArgument Pattern) const {
+
+    SmallVector<UnexpandedParameterPack, 2> Unexpanded;
+    S.collectUnexpandedParameterPacks(Pattern, Unexpanded);
+    if (Unexpanded.size() == 0 ||
+        Packs[0].Saved.getKind() != clang::TemplateArgument::Pack)
+      return {};
+    unsigned PackSize = Packs[0].Saved.pack_size();
+
+    if (std::all_of(Packs.begin() + 1, Packs.end(), [&PackSize](auto P) {
+          return P.Saved.getKind() == TemplateArgument::Pack &&
+                 P.Saved.pack_size() == PackSize;
+        }))
+      return PackSize;
+    return {};
+  }
+
+  /// Determine whether this pack has already been deduced from a previous
+  /// argument.
+  bool isDeducedFromEarlierParameter() const {
+    return DeducedFromEarlierParameter;
+  }
+
----------------
spaits wrote:

This code at the this state(the state in which you wrote this comment) is more complicated then it should be. I was able to make it more simple.

I gave a new name to this function, that describes better what this function does.

We are using the `Saved` packs here that are only modified in the constructors. The `Saved` packs are the previously deduced packs.

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


More information about the cfe-commits mailing list