[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
================
@@ -11757,6 +11791,42 @@ static void DiagnoseBadDeduction(Sema &S, NamedDecl *Found, Decl *Templated,
return;
}
+ // Errors in deduction guides from inherited constructors
+ // will manifest as substitution failures in the return type
+ // partial specialization, so we show a generic diagnostic
+ // in this case.
+ if (auto *DG = dyn_cast<CXXDeductionGuideDecl>(Templated);
+ DG && DG->getSourceDeductionGuideKind() ==
+ CXXDeductionGuideDecl::SourceDeductionGuideKind::
+ InheritedConstructor) {
+ CXXDeductionGuideDecl *Source = DG->getSourceDeductionGuide();
+ assert(Source &&
+ "Inherited constructor deduction guides must have a source");
+
+ auto GetDGDeducedTemplateType =
+ [](CXXDeductionGuideDecl *DG) -> QualType {
+ return QualType(cast<ClassTemplateDecl>(DG->getDeducedTemplate())
+ ->getTemplatedDecl()
+ ->getTypeForDecl(),
+ 0);
+ };
+
+ QualType DeducedRecordType = GetDGDeducedTemplateType(DG);
+ QualType InheritedRecordType = GetDGDeducedTemplateType(Source);
+ S.Diag(Templated->getLocation(),
+ diag::note_ovl_candidate_inherited_constructor_deduction_failure)
+ << DeducedRecordType << InheritedRecordType << TemplateArgString;
+
+ CXXConstructorDecl *Ctor = DG->getCorrespondingConstructor();
+ if (Ctor)
+ S.Diag(
+ Ctor->getBeginLoc(),
+ diag::
+ note_ovl_candidate_inherited_constructor_deduction_failure_source)
+ << InheritedRecordType;
+ return;
----------------
mizvekov wrote:
We already printed the type in the previous note, and we should be pointing to the source location of the constructor anyway, so we can omit that.
Would it also be worth pointing out that this is an implicit deduction guide?
https://github.com/llvm/llvm-project/pull/98788
More information about the cfe-commits
mailing list