[clang] [Clang] Add default arguments to the parameter mapping (PR #192071)

Oliver Hunt via cfe-commits cfe-commits at lists.llvm.org
Tue Apr 14 08:39:50 PDT 2026


================
@@ -2105,6 +2105,25 @@ void SubstituteParameterMappings::buildParameterMapping(
       SemaRef.MarkUsedTemplateParameters(Args->arguments(),
                                          /*Depth=*/0, OccurringIndices);
   }
+
+  // If a parameter is only referenced in a default template argument,
+  // we need to add it to the mapping explicitly.
+  {
+    llvm::SmallVector<TemplateArgument> DefaultArgs;
----------------
ojhunt wrote:

Is this intermediate vector necessary? It looks like `Sema::MarkUsedTemplateParameters(ArrayRef<TemplateArgument>,..)` is just iterating the array and calling `::MarkUsedTemplateParameters` an element at a time. It's seems like adding `MarkUsedTemplateParameter(TemplateArgument&,...)` (to match the existing Expr* version), or even more directly just calling `MarkUsedTemplateParameter({Arg},....)`

OTOH that's screaming premature optimization based on impl knowledge that could change in future given a SmallVector is unlikely to actually need to grow in practice.

I guess the question is more "is this design by choice or requirement?"

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


More information about the cfe-commits mailing list