[clang] [clang] Implement P2582R1: CTAD from inherited constructors (PR #98788)

Matheus Izvekov via cfe-commits cfe-commits at lists.llvm.org
Tue Nov 5 11:32:18 PST 2024


================
@@ -931,12 +935,73 @@ 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 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` ...
+TypeSourceInfo *buildInheritedConstructorDeductionGuideType(
+    Sema &SemaRef, const InheritedConstructorDeductionInfo &Info,
+    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);
----------------
mizvekov wrote:

This is not clear to me, why would the substitution fail if the source is not dependent? Would there instead be simply no substitution? Also why is the derived class not being deducible relevant here, since we are not performing any deductions?

https://github.com/llvm/llvm-project/pull/98788


More information about the cfe-commits mailing list