[clang] [Clang] Implement CWG 2628 "Implicit deduction guides should propagate constraints" (PR #111143)
Younan Zhang via cfe-commits
cfe-commits at lists.llvm.org
Fri Oct 4 06:48:09 PDT 2024
================
@@ -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
More information about the cfe-commits
mailing list