[clang] [clang] Implement P2582R1: CTAD from inherited constructors (PR #98788)
Erich Keane via cfe-commits
cfe-commits at lists.llvm.org
Mon Nov 25 09:47:49 PST 2024
================
@@ -942,34 +946,145 @@ getRHSTemplateDeclAndArgs(Sema &SemaRef, TypeAliasTemplateDecl *AliasTemplate) {
return {Template, AliasRhsTemplateArgs};
}
+struct InheritedConstructorDeductionInfo {
+ // Class template for which we are declaring deduction guides
+ // This is `C` in the standard wording
+ TemplateDecl *DerivedClassTemplate;
+
+ // `template<typename> CC` in the standard wording
+ // This is the type of template that is substituted in the deduction guide
+ // return type `CC<R>`
+ TypeSourceInfo *CCType;
+};
+
+// Build the function type and return type for a deduction guide generated from
+// an inherited constructor C++23 [over.match.class.deduct]p1.10:
+// ... the set contains the guides of A with the return type R
+// of each guide replaced with `typename CC<R>::type` ...
+std::pair<TypeSourceInfo *, QualType>
+buildInheritedConstructorDeductionGuideType(
+ Sema &SemaRef, const InheritedConstructorDeductionInfo &Info,
+ TypeSourceInfo *SourceGuideTSI) {
+ ASTContext &Context = SemaRef.Context;
+ const auto *FPT = SourceGuideTSI->getType()->getAs<FunctionProtoType>();
+ assert(FPT && "Source Guide type should be a FunctionProtoType");
+
+ // This substitution can fail in cases where the source return type
+ // is not dependent and the derived class is not deducible
+ // FIXME: There is currently no diagnostic emitted in this case,
+ // as it is nontrivial to propagate substitution failure messages up
+ // to the point where deduction guides are used-- we do not have a type
+ // with which we can create a deduction guide AST node and must encode the
+ // SFINAE message.
+ Sema::SFINAETrap Trap(SemaRef);
+
+ MultiLevelTemplateArgumentList Args;
+ Args.addOuterTemplateArguments(Info.DerivedClassTemplate,
+ TemplateArgument(FPT->getReturnType()),
+ /*Final=*/false);
+ Args.addOuterRetainedLevels(Info.DerivedClassTemplate->getTemplateDepth());
----------------
erichkeane wrote:
As we sure this is sufficient and shouldn't be calling the `getInstantiationArgs`? It might need help with Deduction guides, but is meant to get the full depth of the deduction guide. But `OuterRetainedLevels` means it won't fully instantiate (and those levels will just not fill anything in). Though is that perhaps what is intended here?
https://github.com/llvm/llvm-project/pull/98788
More information about the cfe-commits
mailing list