[clang] [Clang][C++26] Implement P3865R1 - CTAD for type template template parameters (PR #191409)
Younan Zhang via cfe-commits
cfe-commits at lists.llvm.org
Thu Apr 23 08:19:34 PDT 2026
================
@@ -1615,3 +1582,72 @@ void Sema::DeclareImplicitDeductionGuides(TemplateDecl *Template,
SavedContext.pop();
}
+
+TypeAliasTemplateDecl *Sema::BuildAliasForCTADFromTypeTemplateParameter(
+ TemplateTemplateParmDecl *D, TemplateName Replacement, SourceLocation Loc) {
+
+ // [C++26] [over.match.class.deduct]p3
+ // When resolving a placeholder for a deduced class type where the
+ // template-name designates a type template template parameter P, let A be an
+ // alias template whose template parameter list is that of P and whose
+ // defining-type-id designates the type template template argument with a
+ // simpletemplate-id in which the template-argument-list consists of a list of
+ // identifiers naming each template-parameter of P, with the argument being a
+ // pack expansion if the template-parameter is a pack. A is then used instead
+ // of the original template-name to resolve the placeholder
+
+ LocalInstantiationScope Scope(SemaRef);
+
+ ASTContext &AST = getASTContext();
+ DeclContext *Ctx = CurContext;
+
+ while (Ctx->isRequiresExprBody())
+ Ctx = Ctx->getParent();
+
+ DeclContext *ParentCtx = Ctx;
+ while (isa<FunctionDecl>(ParentCtx))
+ ParentCtx = ParentCtx->isFileContext()
+ ? ParentCtx
+ : getLambdaAwareParentOfDeclContext(ParentCtx);
+
+ MultiLevelTemplateArgumentList MLTAL;
+ if (NamedDecl *Func = dyn_cast<NamedDecl>(Ctx))
+ MLTAL = SemaRef.getTemplateInstantiationArgs(
+ Func, nullptr, false, std::nullopt, false, nullptr, true);
----------------
zyn0217 wrote:
FYI getTemplateInstantiationArgs can take any DeclContexts now, you can get rid of the if and simply pass it as the second argument while leaving the first null. See my commit for details.
https://github.com/llvm/llvm-project/pull/191409
More information about the cfe-commits
mailing list