From 70962f401c17151bbe4e9d95b651d1ad5d30206f Mon Sep 17 00:00:00 2001 From: Younan Zhang Date: Sun, 4 Feb 2024 19:20:19 +0800 Subject: [PATCH] Add comments --- clang/lib/Sema/SemaTemplateInstantiate.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp b/clang/lib/Sema/SemaTemplateInstantiate.cpp index 220883ea9395f0..8faa8c5b5257e9 100644 --- a/clang/lib/Sema/SemaTemplateInstantiate.cpp +++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp @@ -243,6 +243,23 @@ Response HandleFunctionTemplateDecl(const FunctionTemplateDecl *FTD, if (NNS->isInstantiationDependent()) { if (const auto *TSTy = Ty->getAs()) { ArrayRef Arguments = TSTy->template_arguments(); + // Prefer template arguments from the injected-class-type if possible. + // For example, + // ```cpp + // template struct S { + // template void foo(); + // }; + // template template + // ^^^^^^^^^^^^^ InjectedTemplateArgs + // They're of kind TemplateArgument::Pack, not of + // TemplateArgument::Type. + // void S::foo() {} + // ^^^^^^^ + // TSTy->template_arguments() (which are of PackExpansionType) + // ``` + // This meets the contract in + // TreeTransform::TryExpandParameterPacks that the template arguments + // for unexpanded parameters should be of a Pack kind. if (TSTy->isCurrentInstantiation()) { auto *RD = TSTy->getCanonicalTypeInternal()->getAsCXXRecordDecl(); if (ClassTemplateDecl *CTD = RD->getDescribedClassTemplate())