[clang] [Clang] Implement CWG 2628 "Implicit deduction guides should propagate constraints" (PR #111143)
Erich Keane via cfe-commits
cfe-commits at lists.llvm.org
Fri Oct 4 06:36:30 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(
----------------
erichkeane wrote:
This has a certain elegance to it, but I'm not super thrilled with having a BinaryOperator that doesn't have a valid source location. I wonder if we should instead store a collection and check them that way. It makes checking them a little more difficult down the road, but keeps source fidelity.
https://github.com/llvm/llvm-project/pull/111143
More information about the cfe-commits
mailing list