[clang] [Clang] Fix the template argument collection after CWG2369 (PR #147894)

Younan Zhang via cfe-commits cfe-commits at lists.llvm.org
Wed Jul 9 23:20:42 PDT 2025


================
@@ -1078,15 +1078,19 @@ static bool CheckFunctionConstraintsWithoutInstantiation(
   // template. We need the entire list, since the constraint is completely
   // uninstantiated at this point.
 
-  // FIXME: Add TemplateArgs through the 'Innermost' parameter once
-  // the refactoring of getTemplateInstantiationArgs() relands.
-  MultiLevelTemplateArgumentList MLTAL;
-  MLTAL.addOuterTemplateArguments(Template, {}, /*Final=*/false);
-  SemaRef.getTemplateInstantiationArgs(
-      MLTAL, /*D=*/FD, FD,
+  // getTemplateInstantiationArgs uses this instantiation context to find out
+  // template arguments for uninstantiated functions.
+  std::optional<Sema::InstantiatingTemplate> Inst(
+      std::in_place, SemaRef, PointOfInstantiation,
+      Sema::InstantiatingTemplate::ConstraintsCheck{}, Template, TemplateArgs,
+      PointOfInstantiation);
+  if (Inst->isInvalid())
+    return true;
+  MultiLevelTemplateArgumentList MLTAL = SemaRef.getTemplateInstantiationArgs(
+      /*D=*/FD, FD,
       /*Final=*/false, /*Innermost=*/{}, /*RelativeToPrimary=*/true,
       /*Pattern=*/nullptr, /*ForConstraintInstantiation=*/true);
-  MLTAL.replaceInnermostTemplateArguments(Template, TemplateArgs);
+  Inst = std::nullopt;
----------------
zyn0217 wrote:

We will push the same context in CheckConstraintSatisfaction, so I destroy it to avoid duplicate diagnostics

Using an optional was to avoid whitespace changes.. it feels a little weird to me to wrap the function in a block

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


More information about the cfe-commits mailing list