================
@@ -4682,6 +4683,17 @@ bool Sema::InstantiateDefaultArgument(SourceLocation 
CallLoc, FunctionDecl *FD,
                                       ParmVarDecl *Param) {
   assert(Param->hasUninstantiatedDefaultArg());
 
+  NamedDecl *Pattern = FD;
+  std::optional<ArrayRef<TemplateArgument>> Innermost;
+
+  if (FD->isCXXClassMember() &&
+      !isGenericLambdaCallOperatorOrStaticInvokerSpecialization(FD)) {
+    if (FunctionTemplateDecl *FTD = FD->getPrimaryTemplate()) {
+      Pattern = FTD->getFirstDecl();
+      Innermost = FD->getTemplateSpecializationArgs()->asArray();
+    }
+  }
+
----------------
zyn0217 wrote:

Yeah, this is why default arguments are special: the default arguments are 
copied from its first declaration and thus could reference outer template 
parameters outside of the specialization. Can you add some comments around it?

(I added the `ForDefaultArgumentSubstitution` flag because I somehow don't like 
special-casing something that is possibly handled by 
`getTemplateInstantiationArgs`, though that would add one more state to that 
function. So this is a trade-off.)

https://github.com/llvm/llvm-project/pull/106585
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to