[clang] [Clang] Fix various bugs in alias CTAD transform (PR #132061)

Younan Zhang via cfe-commits cfe-commits at lists.llvm.org
Fri Mar 21 07:58:06 PDT 2025


================
@@ -1650,6 +1665,23 @@ namespace {
       return inherited::TransformTemplateArgument(Input, Output, Uneval);
     }
 
+    std::optional<unsigned> ComputeSizeOfPackExprWithoutSubstitution(
+        ArrayRef<TemplateArgument> PackArgs) {
+      // Don't do this when rewriting template parameters for CTAD:
+      //   1) The heuristic needs the unpacked Subst* nodes to figure out the
+      //   expanded size, but this never applies since Subst* nodes are not
+      //   created in rewrite scenarios.
+      //
+      //   2) The heuristic substitutes into the pattern with pack expansion
+      //   suppressed, which does not meet the requirements for argument
+      //   rewriting when template arguments include a non-pack matching against
+      //   a pack, particularly when rewriting an alias CTAD.
+      if (TemplateArgs.isRewrite())
+        return std::nullopt;
----------------
zyn0217 wrote:

I'm not sure I understand what 'dependent template arguments' means here. Did you mean we should run the heuristic if any of the arguments is `TA->isDependent()`? Note that the rewrite template arguments are basically dependent, so I have no idea if that would work.

The underlying issue is that the heuristic doesn't expand the template arguments, so we end up without a valid index for rewrite substitution. It used to assume the packs in the rewrite arguments contained only a single PackExpansionType, but that no longer holds in this scenario because the template arguments we have now are deduced arguments - not those injected template parameters. So I’m a bit worried it might be overkill to skip the heuristic in any conditions other than rewrite - chances are that we'll have Subst* nodes otherwise, right?

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


More information about the cfe-commits mailing list