================
@@ -446,10 +450,46 @@ struct ConvertConstructorToDeductionGuideTransform {
       return nullptr;
     TypeSourceInfo *NewTInfo = TLB.getTypeSourceInfo(SemaRef.Context, NewType);
 
+    // At this point, the function parameters are already 'instantiated' in the
+    // current scope. Substitute into the constructor's trailing
+    // requires-clause, if any.
+    Expr *FunctionTrailingRC = nullptr;
+    if (Expr *RC = CD->getTrailingRequiresClause()) {
+      MultiLevelTemplateArgumentList Args;
+      Args.setKind(TemplateSubstitutionKind::Rewrite);
+      Args.addOuterTemplateArguments(Depth1Args);
+      Args.addOuterRetainedLevel();
+      if (NestedPattern)
+        Args.addOuterRetainedLevels(NestedPattern->getTemplateDepth());
+      ExprResult E = SemaRef.SubstConstraintExprWithoutSatisfaction(RC, Args);
+      if (!E.isUsable())
+        return nullptr;
+      FunctionTrailingRC = E.get();
+    }
+
+    // C++ [over.match.class.deduct]p1:
+    // If C is defined, for each constructor of C, a function template with
+    // the following properties:
+    // [...]
+    // - The associated constraints are the conjunction of the associated
+    // constraints of C and the associated constraints of the constructor, if
+    // any.
+    if (OuterRC) {
+      // The outer template parameters are not transformed, so their
+      // associated constraints don't need substitution.
+      if (!FunctionTrailingRC)
+        FunctionTrailingRC = OuterRC;
+      else
+        FunctionTrailingRC = BinaryOperator::Create(
----------------
zyn0217 wrote:

Hmm, yeah, source fidelity.

But what’s also noteworthy is that we have already checked the class template’s 
constraints prior to checking the CTAD, which is required by the standard.

The binary operator actually changes the constraint-ness in the overload 
resolution against the explicit deduction guides. Though this might not be the 
intention of the DR, see my comments on the test.

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

Reply via email to