[clang] [clang] CTAD: Generate deduction guides for alias templates from non-template explicit deduction guides (PR #96686)
Younan Zhang via cfe-commits
cfe-commits at lists.llvm.org
Tue Jun 25 18:55:09 PDT 2024
================
@@ -3216,6 +3226,44 @@ void DeclareImplicitDeductionGuidesForTypeAlias(
Guides.suppressDiagnostics();
for (auto *G : Guides) {
+ if (auto *DG = dyn_cast<CXXDeductionGuideDecl>(G)) {
+ // The deduction guide is a non-template function decl, we just clone it.
+ auto *FunctionType =
+ SemaRef.Context.getTrivialTypeSourceInfo(DG->getType());
+ FunctionProtoTypeLoc FPTL =
+ FunctionType->getTypeLoc().castAs<FunctionProtoTypeLoc>();
+
+ // Clone the parameters.
+ unsigned ProcessedParamIndex = 0;
+ for (auto *P : DG->parameters()) {
+ auto *TSI = SemaRef.Context.getTrivialTypeSourceInfo(P->getType());
+ ParmVarDecl *NewParam = ParmVarDecl::Create(
+ SemaRef.Context, G->getDeclContext(), P->getBeginLoc(),
+ P->getLocation(), nullptr, TSI->getType(), TSI, SC_None, nullptr);
+ NewParam->setScopeInfo(0, ProcessedParamIndex);
+ FPTL.setParam(ProcessedParamIndex, NewParam);
+ ProcessedParamIndex++;
----------------
zyn0217 wrote:
Do we need to inject the `NewParam` into the new `DeductionGuide` later? i.e. call `NewParam->setOwningFunction()` somewhere below.
https://github.com/llvm/llvm-project/pull/96686
More information about the cfe-commits
mailing list