[clang] [Clang] Handle default template arguments for alias CTAD guides (PR #134807)

Matheus Izvekov via cfe-commits cfe-commits at lists.llvm.org
Tue Apr 15 09:16:24 PDT 2025


================
@@ -690,6 +690,23 @@ SmallVector<unsigned> TemplateParamsReferencedInTemplateArgumentList(
   SemaRef.MarkUsedTemplateParameters(
       DeducedArgs, TemplateParamsList->getDepth(), ReferencedTemplateParams);
 
+  auto MarkDefaultArgs = [&](auto *Param) {
+    if (!Param || !Param->hasDefaultArgument())
+      return;
+    SemaRef.MarkUsedTemplateParameters(
+        Param->getDefaultArgument().getArgument(),
+        TemplateParamsList->getDepth(), ReferencedTemplateParams);
+  };
+
+  for (unsigned Index = 0; Index < TemplateParamsList->size(); ++Index) {
+    if (!ReferencedTemplateParams[Index])
+      continue;
+    auto *Param = TemplateParamsList->getParam(Index);
+    MarkDefaultArgs(dyn_cast<TemplateTypeParmDecl>(Param));
+    MarkDefaultArgs(dyn_cast<NonTypeTemplateParmDecl>(Param));
+    MarkDefaultArgs(dyn_cast<TemplateTemplateParmDecl>(Param));
+  }
+
----------------
mizvekov wrote:

But we could augment ConvertDeducedTemplateArguments with the option of producing rewrites.
Or eventually I think the rewrite flag could be removed entirely, everything being handled automatically.

I am more worried about the big picture here, I find it strange that this operates on the Deduced arguments directly,
which is kind of an arbitrary / clang specific point where the problem is divided,
and that there might be more stuff related to conversions which don't happen correctly in CTAD.

But since I have too much on my plate to dive on this problem now, I digress, lets go ahead :)

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


More information about the cfe-commits mailing list