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

via cfe-commits cfe-commits at lists.llvm.org
Thu Aug 29 06:30:10 PDT 2024


================
@@ -3876,6 +3864,41 @@ TemplateDeductionResult Sema::FinishTemplateArgumentDeduction(
     FD = const_cast<FunctionDecl *>(FDFriend);
     Owner = FD->getLexicalDeclContext();
   }
+
+  // C++20 [temp.deduct.general]p5: [DR2369]
+  // If the function template has associated constraints, those constraints are
+  // checked for satisfaction. If the constraints are not satisfied, type
+  // deduction fails.
+  bool NeedConstraintChecking =
+      !PartialOverloading ||
+      CanonicalBuilder.size() ==
+          FunctionTemplate->getTemplateParameters()->size();
+  // FIXME: We haven't implemented DR2369 for lambdas yet, because we need
+  // the captured variables to be instantiated in the scope.
+  bool IsLambda = isLambdaCallOperator(FD) || isLambdaConversionOperator(FD);
+  if (!IsLambda && NeedConstraintChecking) {
+    if (CheckFunctionConstraintsWithoutInstantiation(
+            Info.getLocation(), FunctionTemplate->getCanonicalDecl(),
+            CanonicalBuilder, Info.AssociatedConstraintsSatisfaction))
+      return TemplateDeductionResult::MiscellaneousDeductionFailure;
+    if (!Info.AssociatedConstraintsSatisfaction.IsSatisfied) {
+      Info.reset(Info.takeSugared(),
+                 TemplateArgumentList::CreateCopy(Context, CanonicalBuilder));
+      return TemplateDeductionResult::ConstraintsNotSatisfied;
+    }
+  }
+  // C++ [temp.deduct.call]p10: [DR1391]
----------------
cor3ntin wrote:

```suggestion
  // C++ [temp.deduct.call]p10 (CWG1391):
```

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


More information about the cfe-commits mailing list