[clang] [clang] Implement P2582R1: CTAD from inherited constructors (PR #98788)
Matheus Izvekov via cfe-commits
cfe-commits at lists.llvm.org
Thu Jul 18 10:12:15 PDT 2024
================
@@ -980,19 +986,69 @@ getRHSTemplateDeclAndArgs(Sema &SemaRef, TypeAliasTemplateDecl *AliasTemplate) {
return {Template, AliasRhsTemplateArgs};
}
+// Build the type for a deduction guide generated from an inherited constructor
+// [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, TypeSourceInfo *DerivedClassMapperType,
+ TemplateDecl *DeducingTemplate, TypeSourceInfo *SourceGuideTSI) {
+ auto &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
+ Sema::SFINAETrap Trap(SemaRef);
+
+ MultiLevelTemplateArgumentList Args;
+ Args.addOuterTemplateArguments(DeducingTemplate,
+ TemplateArgument(FPT->getReturnType()), false);
+ Args.addOuterRetainedLevels(DeducingTemplate->getTemplateDepth());
+ TypeSourceInfo *ReturnTypeTSI =
+ SemaRef.SubstType(DerivedClassMapperType, Args,
+ DeducingTemplate->getBeginLoc(), DeclarationName());
+ if (!ReturnTypeTSI || Trap.hasErrorOccurred())
+ return {nullptr, QualType()};
+ const QualType &ReturnType = ReturnTypeTSI->getType();
----------------
mizvekov wrote:
A QualType is pointer sized, and designed to be copied cheaply, so we never take references to these.
https://github.com/llvm/llvm-project/pull/98788
More information about the cfe-commits
mailing list