[libcxx-commits] [clang] [libcxx] [Clang] Implement CWG2369 "Ordering between constraints and substitution" (PR #102857)

Younan Zhang via libcxx-commits libcxx-commits at lists.llvm.org
Fri Jan 3 09:46:56 PST 2025


================
@@ -1111,12 +1111,55 @@ bool Sema::EnsureTemplateArgumentListConstraints(
   return false;
 }
 
-bool Sema::CheckInstantiatedFunctionTemplateConstraints(
+static bool CheckFunctionConstraintsWithoutInstantiation(
+    Sema &SemaRef, SourceLocation PointOfInstantiation,
+    FunctionTemplateDecl *Template, ArrayRef<TemplateArgument> TemplateArgs,
+    ConstraintSatisfaction &Satisfaction) {
+  SmallVector<const Expr *, 3> TemplateAC;
+  Template->getAssociatedConstraints(TemplateAC);
+  if (TemplateAC.empty()) {
+    Satisfaction.IsSatisfied = true;
+    return false;
+  }
+
+  LocalInstantiationScope Scope(SemaRef);
+
+  FunctionDecl *FD = Template->getTemplatedDecl();
+  // Collect the list of template arguments relative to the 'primary'
+  // 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, std::nullopt, /*Final=*/false);
+  SemaRef.getTemplateInstantiationArgs(
+      MLTAL, /*D=*/FD, FD,
+      /*Final=*/false, /*Innermost=*/std::nullopt, /*RelativeToPrimary=*/true,
+      /*Pattern=*/nullptr, /*ForConstraintInstantiation=*/true);
+  MLTAL.replaceInnermostTemplateArguments(Template, TemplateArgs);
----------------
zyn0217 wrote:

`replaceInnermostTemplateArguments()` has an assertion that the updated AssociatedDecl must match the previously added one. So I'm afraid an 'incorrect' declaration as a placeholder wouldn't work here

Even if we could bypass that restriction, we still wouldn't be able to navigate to the desired lexical declaration context after the inner argument list.

https://github.com/llvm/llvm-project/blob/ee9be864bcc5e3cc89f5f23485db2285ad7119f7/clang/lib/Sema/SemaTemplateInstantiate.cpp#L485-L498

(Where Response::UseNextDecl() is always the semantic DC regardless of the friendness.)

https://github.com/llvm/llvm-project/blob/ee9be864bcc5e3cc89f5f23485db2285ad7119f7/clang/lib/Sema/SemaTemplateInstantiate.cpp#L74-L76)

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


More information about the libcxx-commits mailing list