[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
Sun Nov 3 06:39:09 PST 2024


================
@@ -4008,6 +3996,38 @@ TemplateDeductionResult Sema::FinishTemplateArgumentDeduction(
     Owner = FunctionTemplate->getLexicalDeclContext();
   FunctionDecl *FD = FunctionTemplate->getTemplatedDecl();
 
+  // C++20 [temp.deduct.general]p5: (CWG2369)
+  // If the function template has associated constraints, those constraints are
+  // checked for satisfaction. If the constraints are not satisfied, type
+  // deduction fails.
+  // FIXME: We haven't implemented CWG2369 for lambdas yet, because we need
+  // to figure out how to instantiate lambda captures to the scope without
+  // first instantiating the lambda.
+  bool IsLambda = isLambdaCallOperator(FD) || isLambdaConversionOperator(FD);
+  if (!IsLambda && !IsIncomplete) {
+    if (CheckFunctionTemplateConstraints(
+            Info.getLocation(),
+            FunctionTemplate->getCanonicalDecl()->getTemplatedDecl(),
+            CanonicalBuilder, Info.AssociatedConstraintsSatisfaction))
+      return TemplateDeductionResult::MiscellaneousDeductionFailure;
+    if (!Info.AssociatedConstraintsSatisfaction.IsSatisfied) {
+      Info.reset(Info.takeSugared(),
+                 TemplateArgumentList::CreateCopy(Context, CanonicalBuilder));
----------------
zyn0217 wrote:

(Frankly these lines are also copied from the previous failure handling)

I *guess* the instantiated concept-related nodes that were created during the checking would use the TemplateArgumentLists created on the ASTContext, or rather they would take ownership of the TemplateArgumentList. So, in order for the pilfered argument lists to work for other clients of TemplateDeductionInfo, we have to make a copy of the list.

(I saw the patch that tried to preserve sugars in concepts turn this line into "copy sugared arguments, but do nothing for canonical arguments")

But I'm not entirely sure of such deduction things, so probably @mizvekov would correct my understanding in some way.

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


More information about the libcxx-commits mailing list